fix(rest): Fix type errors when using concrete body types with subclassed RestEndpoint#3845
Merged
fix(rest): Fix type errors when using concrete body types with subclassed RestEndpoint#3845
Conversation
🦋 Changeset detectedLatest commit: 3f62c46 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Size Change: 0 B Total Size: 80.9 kB ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3845 +/- ##
=======================================
Coverage 98.08% 98.08%
=======================================
Files 152 152
Lines 2871 2871
Branches 563 563
=======================================
Hits 2816 2816
Misses 11 11
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When subclassing RestEndpoint with `O extends RestGenerics = any`, concrete body types were rejected because PathArgs<any> produced a restrictive index-signature type. Add `unknown extends S ? any` guard to PathArgs and PathArgsAndSearch so the `any` case passes through without constraint. Uses `unknown extends S` instead of the standard `0 extends 1 & T` IsAny pattern because the latter doesn't resolve correctly inside constrained generic parameters in TypeScript 6. Made-with: Cursor
0e44fd9 to
3f62c46
Compare
Merged
ntucker
added a commit
that referenced
this pull request
Apr 1, 2026
Add `unknown extends O ? any :` before the searchParams conditional in RestEndpoint<O> and RestEndpointConstructorOptions<O>. When subclassing with `O extends RestGenerics = any`, this catches O=any before it reaches PathArgs, preventing the restrictive index-signature type. Includes detailed comment explaining the partial inference limitation where TypeScript may widen path literals to `string` due to complex conditional constructor parameter types. Follows up on #3845 which fixed PathArgs<any> but missed the higher-level propagation through RestEndpointTypes. Made-with: Cursor
ntucker
added a commit
that referenced
this pull request
Apr 1, 2026
Add `unknown extends O ? any :` before the searchParams conditional in RestEndpoint<O> and RestEndpointConstructorOptions<O>. When subclassing with `O extends RestGenerics = any`, this catches O=any before it reaches PathArgs, preventing the restrictive index-signature type. Includes detailed comment explaining the partial inference limitation where TypeScript may widen path literals to `string` due to complex conditional constructor parameter types. Follows up on #3845 which fixed PathArgs<any> but missed the higher-level propagation through RestEndpointTypes. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Subclassing
RestEndpointwithO extends RestGenerics = any— the standard pattern for adding auth headers, custom serialization, etc. — produced type errors when specifying concrete body types.PathArgs<any>evaluated toKeysToArgs<string>({[x:string]: string|number}), a restrictive index-signature that rejected concrete body objects.This was introduced in #3782 (TypeScript 6 upgrade), where
[O['searchParams']] extends [undefined]tuple wrapping was added to preventundefined→anywidening in non-strict mode. That fix was correct for union types, but regressed theO = anycase.Solution
Add
unknown extends S ? anyas the first branch inPathArgsandPathArgsAndSearch. This detectsanyspecifically (unknown extends anyis true,unknown extends stringis false) and short-circuits toany, allowing normal type inference for subclassed endpoints.Uses
unknown extends Sinstead of the standard0 extends 1 & TIsAnypattern because the latter doesn't resolve correctly inside constrained generic parameters (S extends string) in TypeScript 6.Changes:
pathTypes.ts: Addunknown extends S ? anyguard toPathArgsandPathArgsAndSearchpathTypes.test.ts: AssertPathArgs<any>andPathArgsAndSearch<any>equalanytypes.test.ts: Add inheritance tests withAuthdEndpoint<O extends RestGenerics = any>covering constructor, extend, and path changes with concrete body typesOpen questions
N/A
Made with Cursor
Note
Low Risk
Type-level changes to
PathArgs/PathArgsAndSearchaffect TypeScript inference for genericpathvalues; runtime behavior is unchanged and coverage is added via TS tests.Overview
Fixes a TypeScript regression where subclassing
RestEndpointwithO extends RestGenerics = anycaused overly-restrictivepatharg inference, which then rejected concretebodytypes.Updates
PathArgsandPathArgsAndSearchto short-circuit toanywhen the path type isany, and adds TypeScript tests coveringPathArgs<any>plus common subclassing/extend()scenarios. Generated playground.d.tstypes are updated accordingly, and a patch changeset documents the fix.Written by Cursor Bugbot for commit 3f62c46. This will update automatically on new commits. Configure here.