fix(rest): SoftPathArgs for widened path inference in RestEndpoint subclasses#3847
fix(rest): SoftPathArgs for widened path inference in RestEndpoint subclasses#3847
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 3877777 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 |
|
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 #3847 +/- ##
=======================================
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:
|
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
13531fd to
68b8b29
Compare
…s constructors Introduce SoftPathArgs<P> that resolves PathArgs<string> to `unknown`, preventing union overloads in ParamFetchWithBody when path widens. Infer method as POST when explicit body is provided. Add comprehensive type tests for widened-path endpoints (all callback overrides: getOptimisticResponse, key, url, process) and resource() with AuthdEndpoint subclass (extend per-endpoint, object form, function form). Update src-4.0-types legacy replacement with SoftPathArgs export. Made-with: Cursor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Follows up on #3845.
Motivation
When subclassing
RestEndpointwithO extends RestGenerics = any, TypeScript can widen path literals (e.g.,'/users') tostringduring constructor inference. This causedPathArgs<string>to produce a restrictive index-signature type, which in turn created union overloads inParamFetchWithBody. These unions madegetOptimisticResponse,key,url, andprocesscallbacks unassignable — their parameter types didn't match the union of possible argument tuples.Additionally, endpoints with an explicit
bodybut nomethodwere defaulting toGET, making the body optional instead of required.Solution
SoftPathArgs<P>— new utility type inpathTypes.tsthat collapsesPathArgs<string>tounknown(the identity for&), preventing the problematic union overloads while preserving full inference for literal paths.bodyis explicitly provided and notundefined,RestEndpointConstructorOptionsandRestEndpointnow inferPOSTas the default method forOptionsToBodyArgument, making the body required.SoftPathArgsadded tosrc-4.0-types/pathTypes.d.tsfor TS 4.0 compatibility.Parameters<F>-dependent callbacks (getOptimisticResponse,key,url,process) with widened pathssearchParams+ body, params + body.extend()on widened-path endpointsresource()withAuthdEndpointsubclass + all extend patterns (per-endpoint, object form, function form)Note
Medium Risk
Type-only changes to
RestEndpointinference could change TypeScript call signatures (e.g., body becoming required whenmethodis omitted), potentially surfacing new compile errors in downstream code, though runtime behavior is unaffected.Overview
Fixes TypeScript inference for
RestEndpointsubclasses wherepathliterals get widened tostring, ensuring constructor callbacks likegetOptimisticResponse,key,url, andprocessreceive usable parameter types (including whensearchParams: undefinedis set).Updates
RestEndpointtyping to infer the defaultmethodfrom an explicitly providedbody(treating it asPOST), sobodyremains required across.extend()whenmethodwas omitted. AddsSoftPathArgs(including TS4.0 d.ts + playground types) and expands TypeScript tests to cover widened paths, subclassing,extend(), andresource()integration. Also fixes incorrect intra-blog links in the v0.15 release post.Written by Cursor Bugbot for commit 3877777. This will update automatically on new commits. Configure here.