Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript compliation issue - Type 'RequestInit' is not assignable to type 'never' #367

Open
YaronRosh opened this issue Apr 1, 2024 · 7 comments

Comments

@YaronRosh
Copy link

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

@RobertCraigie
Copy link
Collaborator

Can you share your tsconfig? This is likely an issue in your config.

@YaronRosh
Copy link
Author

YaronRosh commented Apr 1, 2024

{
  "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"
  ]
}

@rattrayalex
Copy link
Collaborator

rattrayalex commented Apr 1, 2024

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

@YaronRosh
Copy link
Author

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>): {
       ~~~~~~~~~~~~

@rattrayalex
Copy link
Collaborator

Got it. Does "moduleResolution": "nodeNext"help?

@amosd92
Copy link

amosd92 commented Apr 3, 2024

Answering on behalf of Yaron, it didn't help as well.

@rattrayalex
Copy link
Collaborator

hmm… that's surprising. Can you share a codesandbox with minimal repro?

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

No branches or pull requests

4 participants