Skip to content

node.js fetch is wrongly typed #4271

@bpasero

Description

@bpasero

Missing / Incorrect Definition

Image

https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata

But thats not the case.

Sample Code

async function foo() {
    const res = await fetch('https://example.com');
    console.log(await res.bytes()); // error: Property 'bytes' does not exist on type 'Response'.ts(2339)
}

foo();

Using tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "lib": ["ESNext"],
    "types": [
        "node"
    ],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["index.ts"],
  "exclude": ["node_modules"]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions