fix(types): fix the type definitions for factory models and config, aβ¦#408
fix(types): fix the type definitions for factory models and config, aβ¦#408liyown wants to merge 2 commits intoTanStack:mainfrom
Conversation
β¦nd add InferRestArgs utility type
β¦ving unused InferConfig type
π WalkthroughWalkthroughThe Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~12 minutes Poem
π₯ Pre-merge checks | β 4 | β 1β Failed checks (1 warning)
β Passed checks (4 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
π€ Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/typescript/ai/src/extend-adapter.ts`:
- Line 113: The generic constraint for InferRestArgs uses an invalid
rest-parameter type; update the constraint on TFactory from using (...args: any)
to a valid rest tuple type such as (...args: any[]) => any so TypeScript accepts
it. Locate the type alias InferRestArgs and change its constraint to TFactory
extends (...args: any[]) => any (and if other similar generic constraints exist
in the same file, apply the same tuple/array rest fix).
πͺ Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
βΉοΈ Review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 01b3cf38-4277-449f-8500-e5e7a4f22123
π Files selected for processing (1)
packages/typescript/ai/src/extend-adapter.ts
| /** | ||
| * Extracts all parameter types after the first parameter from a function. | ||
| */ | ||
| type InferRestArgs<TFactory extends (...args: any) => any> = |
There was a problem hiding this comment.
π§© Analysis chain
π Web query:
Does TypeScript allow a rest parameter type annotation of any(e.g.,(...args: any) => any), or must it be an array/tuple type like any[]?
π‘ Result:
No, TypeScript does not allow a rest parameter type annotation of any like (...args: any) => any. The type annotation for rest parameters must be an array type like any[], a specific array type such as number[], or a tuple type.
Citations:
- 1: https://www.typescriptlang.org/docs/handbook/2/functions.html
- 2: https://www.typescriptlang.org/docs/handbook/functions.html
- 3: https://www.typescriptlang.org/docs/handbook/2/functions
π Script executed:
head -n 120 packages/typescript/ai/src/extend-adapter.ts | tail -n 20Repository: TanStack/ai
Length of output: 541
Fix invalid rest-parameter typing in generic constraint.
Line 113 uses (...args: any), but TypeScript requires rest parameters to be array or tuple types (e.g., any[]). This will cause a TypeScript compilation error.
Suggested fix
-type InferRestArgs<TFactory extends (...args: any) => any> =
+type InferRestArgs<TFactory extends (...args: any[]) => any> =
Parameters<TFactory> extends [any, ...infer Rest] ? Rest : []π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| type InferRestArgs<TFactory extends (...args: any) => any> = | |
| type InferRestArgs<TFactory extends (...args: any[]) => any> = | |
| Parameters<TFactory> extends [any, ...infer Rest] ? Rest : [] |
π€ Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/typescript/ai/src/extend-adapter.ts` at line 113, The generic
constraint for InferRestArgs uses an invalid rest-parameter type; update the
constraint on TFactory from using (...args: any) to a valid rest tuple type such
as (...args: any[]) => any so TypeScript accepts it. Locate the type alias
InferRestArgs and change its constraint to TFactory extends (...args: any[]) =>
any (and if other similar generic constraints exist in the same file, apply the
same tuple/array rest fix).
π― Changes
fix #407
β Checklist
pnpm run test:pr.Summary by CodeRabbit