Typescript compliation issue - Type 'RequestInit' is not assignable to type 'never'
YaronRosh opened this issue · comments
having compilation issue with the @anthropic-ai/bedrock-sdk
, using in node js + ts
../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:45:5 - error TS2416: Property 'buildRequest' in type 'AnthropicBedrock' is not assignable to the same property in base type 'APIClient'.
Type '{ (options: FinalRequestOptions<unknown>): { req: RequestInit; url: string; timeout: number; }; (options: FinalRequestOptions<unknown>): { ...; }; }' is not assignable to type '<Req>(options: FinalRequestOptions<Req>) => { req: never; url: string; timeout: number; }'.
Call signature return types '{ req: RequestInit; url: string; timeout: number; }' and '{ req: never; url: string; timeout: number; }' are incompatible.
The types of 'req' are incompatible between these types.
Type 'RequestInit' is not assignable to type 'never'.
45 buildRequest(options: Core.FinalRequestOptions<unknown>): {
~~~~~~~~~~~~
Found 1 error in ../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:45
using
@anthropic-ai/bedrock-sdk
: 0.9.2
typescript
: 5.2.2
Can you share your tsconfig? This is likely an issue in your config.
{
"compilerOptions": {
"outDir": "dist",
"incremental": true,
"sourceMap": true,
"lib": ["esnext", "dom"],
"jsx": "react",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"module": "commonjs",
"rootDir": ".",
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "Node",
"allowJs": true,
"resolveJsonModule": true
},
"include": [
"src",
"__tests__"
],
"exclude": [
"node_modules",
"./_isolated_",
"./workspaces",
"**/dist"
]
}
Can you try "moduleResolution": "nodeNext"
instead of "Node"
?
If that presents other challenges for you, you can try adding this line before your first import of the package:
import '@anthropic-ai/sdk/shims/node'
More information here: https://github.com/anthropics/anthropic-sdk-typescript/tree/main/src/_shims#readme
it now fails on something else
with or without the shim
import '@anthropic-ai/sdk/shims/node'
../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:41:15 - error TS2416: Property 'prepareRequest' in type 'AnthropicBedrock' is not assignable to the same property in base type 'APIClient'.
Type '(request: RequestInit, { url, options }: { url: string; options: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@anthropic-ai/sdk/core").FinalRequestOptions<unknown>; }) => Promise<...>' is not assignable to type '(request: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@types/node-fetch/index").RequestInit, { url, options }: { url: string; options: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@anthropic-ai/sdk/core").FinalRequestOptions<unknown>; }) => Promise<...>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'import("/node_modules/@types/node-fetch/index").RequestInit' is not assignable to type 'RequestInit'.
Types of property 'body' are incompatible.
Type 'import("/node_modules/@types/node-fetch/index").BodyInit' is not assignable to type 'BodyInit'.
Type 'ReadableStream' is not assignable to type 'BodyInit'.
Type 'ReadableStream' is missing the following properties from type 'ReadableStream<any>': locked, cancel, getReader, pipeThrough, and 3 more.
41 protected prepareRequest(request: RequestInit, { url, options }: {
~~~~~~~~~~~~~~
../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:45:5 - error TS2416: Property 'buildRequest' in type 'AnthropicBedrock' is not assignable to the same property in base type 'APIClient'.
Type '(options: FinalRequestOptions<unknown>) => { req: RequestInit; url: string; timeout: number; }' is not assignable to type '<Req>(options: FinalRequestOptions<Req>) => { req: RequestInit; url: string; timeout: number; }'.
Call signature return types '{ req: RequestInit; url: string; timeout: number; }' and '{ req: RequestInit; url: string; timeout: number; }' are incompatible.
The types of 'req.body' are incompatible between these types.
Type 'BodyInit' is not assignable to type 'import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@types/node-fetch/index").BodyInit'.
Type 'Blob' is not assignable to type 'BodyInit'.
Type 'Blob' is missing the following properties from type 'URLSearchParams': append, delete, entries, forEach, and 8 more.
45 buildRequest(options: Core.FinalRequestOptions<unknown>): {
~~~~~~~~~~~~
Got it. Does "moduleResolution": "nodeNext"
help?
Answering on behalf of Yaron, it didn't help as well.
hmm… that's surprising. Can you share a codesandbox with minimal repro?