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

RequestInit - Type '"timeout"' is not assignable to type 'keyof RequestInit' #59314

Open
agrofcsik opened this issue Mar 17, 2022 · 1 comment

Comments

@agrofcsik
Copy link

@types/node-fetch version: v2.6.1
RequestInit is found in: node_modules/node-fetch/@types/index.d.ts

@types/make-fetch-happen: v9.0.2
node_modules/@types/make-fetch-happen/index.d.ts:25:9

Full Error:

node_modules/@types/make-fetch-happen/index.d.ts:25:9 - error TS2344: Type '"timeout" | "headers" | "agent" | "method" | "body" | "size" | "follow" | "redirect" | "compress"' does not satisfy the constraint 'keyof RequestInit'.
  Type '"timeout"' is not assignable to type 'keyof RequestInit'.

25         'method' | 'body' | 'redirect' | 'follow' | 'timeout' | 'compress' | 'size' | 'headers' | 'agent'
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@nex3
Copy link
Contributor

nex3 commented Nov 2, 2022

Dug into this a bit. Here are the relevant facts:

  • The types in @types/node-fetch are for 2.6, for reasons detailed in node-fetch: restore types (for v2), update version, allow agent: false #58693.

  • node-fetch 3.x now ships its own type declarations.

  • Among other changes, node-fetch 3.x no longer includes a timeout option in RequestInit (as per source and docs).

  • make-fetch-happen never actually depended on node-fetch.

  • Despite this, @types/make-fetch-happen uses node-fetch's Request and RequestInit types.

  • If you depend on @types/make-fetch-happen, the actual types it uses in practice will depend on which other packages you have installed. So if you (transitively) depend on node-fetch 3.x, it'll use the types declared there; if you don't, it'll use @types/node-fetch 2.6.

  • But @types/make-fetch-happen is incompatible with node-fetch 3.x's types because it declares

    type NodeFetchOptions = Pick<
        RequestInit,
        'method' | 'body' | 'redirect' | 'follow' | 'timeout' | 'compress' | 'size' | 'headers' | 'agent'
    >;

    ...and if RequestInit doesn't have a 'timeout' field, this seems to mark 'timeout' as required in NodeFetchOptions.

This essentially creates a time bomb: anyone using @types/make-fetch-happen will be broken once any of their other dependencies starts using node-fetch 3.x.

I believe the root issue is that @types/make-fetch-happenshould never have used types from a package that themake-fetch-happenimplementation didn't depend on, and the fix would be removing that dependency edge and explicitly declaring the type forNodeFetchOptionsandRequest`.

The only workaround I can find so far is to either drop dependencies on make-fetch-happen or node-fetch 3.x.

cc @abernix who wrote the original #50339

nex3 added a commit to sass/embedded-host-node that referenced this issue Nov 2, 2022
This reverts commit 11ecf3c.

Works around DefinitelyTyped/DefinitelyTyped#59314.

Now that we aren't downloading anything on end users' systems, we
don't have a strong need to respect npm's proxy options.
nex3 added a commit to sass/embedded-host-node that referenced this issue Nov 2, 2022
This reverts commit 11ecf3c.

Works around DefinitelyTyped/DefinitelyTyped#59314.

Now that we aren't downloading anything on end users' systems, we
don't have a strong need to respect npm's proxy options.
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

2 participants