Skip to content

feat(ratelimit): default the middleware input type to unknown - #2033

Closed
dinwwwh wants to merge 1 commit into
middleapi:mainfrom
dinwwwh:claude/ratelimit-middleware-tinput-4cd021
Closed

dinwwwh wants to merge 1 commit into
middleapi:mainfrom
dinwwwh:claude/ratelimit-middleware-tinput-4cd021

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Sep 16, 2026

Copy link
Copy Markdown
Member

ratelimit and RateLimitMiddlewareOptions now default TInput to unknown. Defining the middleware standalone only needs the context type argument, e.g. ratelimit<{ ratelimiter: RateLimiter }>({ ... }), where TypeScript previously demanded both type arguments.

Behavior

  • Standalone middleware definitions no longer fail with "Expected 2 type arguments"; the input is unknown and the middleware plugs into any procedure input.
  • Inline .use(ratelimit({ ... })) is unchanged, since both type arguments are still inferred from the call site.

Testing

  • Type tests cover the standalone factory call and the one-argument options type; they fail without the default.
  • Ratelimit runtime tests and eslint pass.

@dinwwwh dinwwwh closed this Sep 16, 2026
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the full one-commit diff of PR #2033, which relaxes the type-parameter requirement for the ratelimit middleware.

  • Defaulted input typeRateLimitMiddlewareOptions<TInContext, TInput = unknown> (middleware.ts:22) and ratelimit<TInContext, TInput = unknown> (middleware.ts:61) now allow a standalone middleware definition with only the context type argument. The declared return type Middleware<TInContext, object, TInput, any, object> is unchanged, so this is backwards compatible — the default only applies when inference yields no candidate, and inline .use(ratelimit({...})) still infers TInput from the call site.
  • Standalone type tests — the new describe('ratelimit standalone') block pins the one-argument factory call and the one-argument options type, asserts input is unknown in both callbacks, and keeps the @ts-expect-error for a context missing rateLimiter, so the default doesn't loosen context checking.

Verified locally: root tsc -b . exits 0 (the root tsconfig is what validates *.test-d.ts) and eslint --max-warnings=0 on both changed files exits 0. unknown is the sound choice over any here — accessing an unknown field still requires narrowing.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@codspeed

codspeed Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing dinwwwh:claude/ratelimit-middleware-tinput-4cd021 (1d05772) with main (9b9b44b)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant