Skip to content

Type issues when using undici #2562

@penx

Description

@penx

openapi-fetch version

0.15.0

Description

When using undici's fetch and Request for the custom fetch and Request options, I get typescript errors. Looking at previous pull requests, it looks like this should be supported, so I assume this is a bug:

Reproduction

import createClient from "openapi-fetch";
import { Request, fetch } from "undici";

export const client = createClient({
  fetch,
  Request,
});

Results in 2 typescript issues:

Type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>' is not assignable to type '(input: Request) => Promise<Response>'.
  Types of parameters 'input' and 'input' are incompatible.
    Type 'Request' is not assignable to type 'RequestInfo'.
      Property 'duplex' is missing in type 'Request' but required in type 'import("/node_modules/undici/types/fetch").Request'.ts(2322)
Type 'typeof Request' is not assignable to type '{ new (input: RequestInfo | URL, init?: RequestInit | undefined): Request; prototype: Request; }'.
  Types of property 'prototype' are incompatible.
    Property 'bytes' is missing in type 'import("/node_modules/undici/types/fetch").Request' but required in type 'Request'.ts(2322)

Expected result

Using fetch and Request from undici should not result in typescript errors.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions