From 6695f193daf1652e7620ff138d5b25597332ffb3 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Mon, 2 Nov 2026 16:11:09 +0800 Subject: [PATCH] fix(types): add optional delta to RateLimitOptions The Rate Limiting binding accepts an optional `delta` in `limit()` to add a weighted amount to the counter instead of 1. Expose it in the types and add a type test. Co-Authored-By: Claude Opus 5.5 (1M context) --- types/defines/ratelimit.d.ts | 6 ++++++ .../generated-snapshot/experimental/index.d.ts | 6 ++++++ types/generated-snapshot/experimental/index.ts | 6 ++++++ types/generated-snapshot/index.d.ts | 6 ++++++ types/generated-snapshot/index.ts | 6 ++++++ types/test/types/ratelimit.ts | 17 +++++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 types/test/types/ratelimit.ts diff --git a/types/defines/ratelimit.d.ts b/types/defines/ratelimit.d.ts index a37ec6013fb..388c45bfad3 100644 --- a/types/defines/ratelimit.d.ts +++ b/types/defines/ratelimit.d.ts @@ -1,5 +1,11 @@ interface RateLimitOptions { key: string + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number } interface RateLimitOutcome { diff --git a/types/generated-snapshot/experimental/index.d.ts b/types/generated-snapshot/experimental/index.d.ts index 980b5a2a3d9..3bf728da707 100755 --- a/types/generated-snapshot/experimental/index.d.ts +++ b/types/generated-snapshot/experimental/index.d.ts @@ -16552,6 +16552,12 @@ interface JsonWebKeyWithKid extends JsonWebKey { } interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/experimental/index.ts b/types/generated-snapshot/experimental/index.ts index bbc91cb62ed..b1ed454250e 100755 --- a/types/generated-snapshot/experimental/index.ts +++ b/types/generated-snapshot/experimental/index.ts @@ -16462,6 +16462,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey { } export interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } export interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/index.d.ts b/types/generated-snapshot/index.d.ts index a11a5f259cb..7686e23bda0 100755 --- a/types/generated-snapshot/index.d.ts +++ b/types/generated-snapshot/index.d.ts @@ -16186,6 +16186,12 @@ interface JsonWebKeyWithKid extends JsonWebKey { } interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/index.ts b/types/generated-snapshot/index.ts index 2577a9a6821..abcc25d22dc 100755 --- a/types/generated-snapshot/index.ts +++ b/types/generated-snapshot/index.ts @@ -16099,6 +16099,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey { } export interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } export interface RateLimitOutcome { success: boolean; diff --git a/types/test/types/ratelimit.ts b/types/test/types/ratelimit.ts new file mode 100644 index 00000000000..a72d89dbd1e --- /dev/null +++ b/types/test/types/ratelimit.ts @@ -0,0 +1,17 @@ +// Copyright (c) 2026 Cloudflare, Inc. +// Licensed under the Apache 2.0 license found in the LICENSE file or at: +// https://opensource.org/licenses/Apache-2.0 + +function expectType(_value: T) {} + +declare const limiter: RateLimit; + +expectType>(limiter.limit({ key: 'user-123' })); +expectType>( + limiter.limit({ key: 'user-123', delta: 5 }) +); + +// @ts-expect-error `delta` must be a number. +limiter.limit({ key: 'user-123', delta: '5' }); +// @ts-expect-error `key` is required. +limiter.limit({ delta: 5 });