Skip to content

fix(types): fix the type definitions for factory models and config, a…#408

Open
liyown wants to merge 2 commits intoTanStack:mainfrom
liyown:fix/fix-extend-adapter-error-infer-type
Open

fix(types): fix the type definitions for factory models and config, a…#408
liyown wants to merge 2 commits intoTanStack:mainfrom
liyown:fix/fix-extend-adapter-error-infer-type

Conversation

@liyown
Copy link
Copy Markdown

@liyown liyown commented Mar 29, 2026

🎯 Changes

fix #407

βœ… Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

Summary by CodeRabbit

  • Refactor
    • Enhanced type inference for adapter configuration to provide improved flexibility with factory parameters.

15367279252qq.com added 2 commits March 30, 2026 01:04
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

πŸ“ Walkthrough

Walkthrough

The extendAdapter function's type signature is refined to better infer and preserve all parameters from the underlying adapter factory. A new InferRestArgs type helper extracts trailing parameters, and the generic constraint is updated to explicitly require a model parameter as the first argument.

Changes

Cohort / File(s) Summary
Type Signature Refinement
packages/typescript/ai/src/extend-adapter.ts
Removed InferConfig type and conditional config logic. Introduced InferRestArgs to extract remaining parameters. Updated generic constraint to explicitly require (model: any, ...args) signature. Replaced explicit return type with type cast preserving all parameter inference from the factory.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A tale of types, now crystal clear,
Where factories whisper parameters near,
No more confusion, the model stands tall,
Rest args flow freely, extending it all! ✨

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. It references issue #407 but lacks detail about what specific changes were made and their motivation, and the 'Release Impact' section is missing. Expand the description to explain the specific type definition changes and clarify the release impact with a changeset or justification if docs-only.
βœ… Passed checks (4 passed)
Check name Status Explanation
Title check βœ… Passed The title 'fix(types): fix the type definitions for factory models and config, a…' is related to the main changes (type definitions fix) but is truncated and generic with repeated 'fix'.
Linked Issues check βœ… Passed The PR successfully addresses issue #407 by fixing type inference for factory models, enabling extendAdapter to work consistently with both createAnthropicChat and anthropicText factories.
Out of Scope Changes check βœ… Passed All changes in extend-adapter.ts are scoped to fixing type definitions and inference, directly addressing the linked issue #407 with no extraneous modifications.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a8a4465 and 0ccbcdf.

πŸ“’ 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> =
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.

⚠️ Potential issue | πŸ”΄ Critical

🧩 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:


🏁 Script executed:

head -n 120 packages/typescript/ai/src/extend-adapter.ts | tail -n 20

Repository: 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.

Suggested change
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).

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.

Is there any way to extend models but with createAnthropicChat rather than anthropicText?

1 participant