Skip to content

refactor(ai-provider): Replace any with explicit model types (#879) - #1242

Open
DAmensah27 wants to merge 1 commit into
Vets-Who-Code:masterfrom
DAmensah27:fix/879-ai-provider-types
Open

refactor(ai-provider): Replace any with explicit model types (#879)#1242
DAmensah27 wants to merge 1 commit into
Vets-Who-Code:masterfrom
DAmensah27:fix/879-ai-provider-types

Conversation

@DAmensah27

Copy link
Copy Markdown

Replace any with LanguageModel in the AI provider utility

Closes #879.

What & why. src/lib/ai-provider.ts used any in three places that all describe the same thing — the AI SDK model instance returned by openai() / google() / azure(). This PR types them with LanguageModel from the ai package (AI SDK v5), restoring compile-time safety and editor autocomplete with no runtime change.

Changes.

  • + import type { LanguageModel } from "ai";
  • ProviderConfig.instance: anyLanguageModel
  • getAIModelWithFallback() return model: anyLanguageModel
  • tryProvidersWithFallback() operation: (model: any) => …(model: LanguageModel) => …

Note on the type. The issue suggested LanguageModel from @ai-sdk/provider, but in the installed v5 that package exports LanguageModelV2 and is only a transitive dependency. ai (a direct dependency) exports LanguageModel = string | LanguageModelV2, which the concrete model instances satisfy and which is the type the SDK's own APIs (e.g. generateText) consume — so I imported from ai.

Testing. Type-only change (annotation erased at compile time). npm run typecheck passes with no errors; biome lint is clean on the file.

…o-Code#879)

Replace the three `any` types in src/lib/ai-provider.ts with the
`LanguageModel` type from the `ai` package (AI SDK v5), restoring type
safety on the provider instance and the two fallback helpers:

- ProviderConfig.instance
- getAIModelWithFallback() return model
- tryProvidersWithFallback() operation callback parameter

`LanguageModel` is the idiomatic public type exported by `ai` (a direct
dependency) and is what the openai()/google()/azure() model instances
resolve to. tsc -p tsconfig.json passes with no errors.
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@DAmensah27 is attempting to deploy a commit to the vetswhocode-web-app Team on Vercel.

A member of the Team first needs to authorize it.

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.

Add TypeScript types to AI Provider utility (replace 'any')

1 participant