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 · 12 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?

@S-unya
Copy link

S-unya commented Aug 5, 2024

I also get exactly the same error when I set "module": "NodeNext", "moduleResolution": "NodeNext",. I also started from the same error, pretty much copying the example:

import AnthropicBedrock from '@anthropic-ai/bedrock-sdk';

const createInput = async (messages) => {
  const client = new AnthropicBedrock({
    awsAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    awsSecretKey: process.env.AWS_ACCESS_KEY_ID,
    awsRegion: process.env.AWS_DEFAULT_REGION,
  });

  const message = await client.messages.create({
    model: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
    max_tokens: 256,
    messages
  });

  return message;
}

@rattrayalex
Copy link
Collaborator

Can you share a codesandbox with a minimal repro? Without more details, we can't really directly fix this.

You might also try import '@anthropic-ai/sdk/shims/node' or import '@anthropic-ai/sdk/shims/web' before your first import of the SDK.

@S-unya
Copy link

S-unya commented Aug 13, 2024

This repro is pretty much the same as the docs; please run npm run build in this, https://codesandbox.io/p/sandbox/angry-thunder-ll36v2. Note it is the tsc command that fails.

I worked around this by converting the ts file to a js file with JSDOC comments, but that is a work around, not a "solution"

@rattrayalex
Copy link
Collaborator

Thanks, we'll take a look!

@RobertCraigie
Copy link
Collaborator

@S-unya unfortunately I'm getting a "Sandbox not found" error message from https://codesandbox.io/p/sandbox/angry-thunder-ll36v2, is it private?

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

5 participants