Conversation
process(value, params) passed to RestEndpoint.extend() or resource().extend() typed params as any. Type them from the extended endpoint's path, searchParams and body, including a path set in the same call. Endpoints callable several ways (optional params or body) merge their argument lists position-wise, so every way the endpoint is called type-checks. extend() options are now constrained by ExtendableRestGenerics (PartialRestGenerics without process), so TypeScript 4.1-5.x contextually type process() instead of reporting implicit any. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bv3zm61qvR8ytLLib2KVq3
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: e43d854 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 |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bv3zm61qvR8ytLLib2KVq3
|
Staff engineer (Cursor agent): LGTM on FOLLOW_UP (after merge, not a change to this PR):
|
|
Size Change: 0 B Total Size: 103 kB ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4183 +/- ##
==========================================
+ Coverage 98.06% 98.08% +0.02%
==========================================
Files 163 165 +2
Lines 3098 3139 +41
Branches 617 625 +8
==========================================
+ Hits 3038 3079 +41
Misses 18 18
Partials 42 42 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…s scope Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bv3zm61qvR8ytLLib2KVq3
|
Re the Staff follow-ups, both handled in e43d854:
The /simplify altitude review also noted that the constructor ( Generated by Claude Code |
Requested by Nathaniel · project thread
Follow-up from the review on #4173.
Motivation
process(value, params)passed toRestEndpoint.extend()orresource().extend()gotparamstyped asany, so reading a param the endpoint doesn't have compiled and returnedundefinedat runtime.Endpoints whose params are optional pass
paramsas possiblyundefined(params?.page). On TypeScript 4.1–5.x, an.extend()that setspathtogether withprocess(value, params)no longer fails with "implicitly has an 'any' type" understrict.Solution
RestEndpointExtendOptionsgetsprocess?(value, ...args: ProcessArgs<Parameters<OptionsToFunction<O, E, F>>>), so params follow the resulting endpoint (apathin the same call wins).ProcessArgsmerges call-shape unions like[params] | []or[params, body] | [body]position-wise into optional elements, soprocess(value, params, body)keeps compiling for endpoints callable several ways.extend()options (RestEndpoint and bothresource().extend(key, …)overloads, including the hand-written TS 4.1 declarations) are constrained by a newExtendableRestGenerics(PartialRestGenericswithoutprocess). With the old constraint, TS ≤ 5.3 saw twoprocesssignatures and gave up on contextual typing (implicit any).Zero loss: with every
@ts-expect-errorneutralized, diagnostics are identical before/after on TS 6 (API), TS 7 (tsc), and TS 4.0/4.1/4.3/4.8/5.3 (example typetests + libcheck + the new test), except the new expected errors; the TS7006 implicit-any errors on master for path+process disappear. TS 4.0 keepsparams: any(its simplified declarations), with no new errors.Type-check cost (instantiations, TS 6 / TS 7 check time, vs master):
process, new)The added cost is TypeScript now actually checking
processbodies against real param types; endpoints withoutprocesspay about 1%.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bv3zm61qvR8ytLLib2KVq3
Generated by Claude Code
Note
Medium Risk
Compile-time-only change that can break builds on upgrade when existing
process()callbacks use wrong or unchecked params; runtime fetch behavior is unchanged.Overview
@data-client/restnow types the arguments passed toprocess()inside.extend()(includingresource().extend('get', …)), derived from the resulting endpoint’spath,searchParams, andbody—including apathoverridden in the same.extend()call. Wrong param names become compile-time errors instead of silentundefinedat runtime; optional call shapes useparams?.…where needed.The typing work adds
ProcessArgsto merge optional fetch argument tuples, splitsExtendableRestGenerics(noprocess) fromPartialRestGenericsso TypeScript ≤5.3 can contextually typeprocesswithout implicitany, and wires the same constraints through TS 4.1 declaration shims. No runtime behavior changes.Docs (RestEndpoint
processsection), a changeset, v0.19 blog notes, andextendProcess.test.tstype regressions document and lock in the behavior. Upgrading may surface new TypeScript errors in existingprocess()implementations that were previously unchecked.Reviewed by Cursor Bugbot for commit e43d854. Bugbot is set up for automated code reviews on this repo. Configure here.