Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions packages/typescript/ai/src/extend-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ type InferFactoryModels<TFactory> = TFactory extends (
: string
: string

/**
* Infer the config parameter type from an adapter factory function.
*/
type InferConfig<TFactory> = TFactory extends (
model: any,
config?: infer TConfig,
) => any
? TConfig
: undefined

/**
* Infer the adapter return type from a factory function.
Expand All @@ -116,6 +107,12 @@ type InferAdapterReturn<TFactory> = TFactory extends (
? TReturn
: never

/**
* 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).

Parameters<TFactory> extends [any, ...infer Rest] ? Rest : []

// ===========================
// extendAdapter Function
// ===========================
Expand Down Expand Up @@ -164,19 +161,17 @@ type InferAdapterReturn<TFactory> = TFactory extends (
* ```
*/
export function extendAdapter<
TFactory extends (...args: Array<any>) => any,
TFactory extends (model: any, ...args: Array<any>) => any,
const TDefs extends ReadonlyArray<ExtendedModelDef>,
>(
factory: TFactory,
_customModels: TDefs,
): (
model: InferFactoryModels<TFactory> | ExtractCustomModelNames<TDefs>,
...args: InferConfig<TFactory> extends undefined
? []
: [config?: InferConfig<TFactory>]
) => InferAdapterReturn<TFactory> {
) {
// At runtime, we simply pass through to the original factory.
// The _customModels parameter is only used for type inference.
// No runtime validation - users are trusted to pass valid model names.
return factory as any
}
return factory as unknown as (
model: InferFactoryModels<TFactory> | ExtractCustomModelNames<TDefs>,
...args: InferRestArgs<TFactory>
) => InferAdapterReturn<TFactory>
}