question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch is incompatible with the GlobalFetch['fetch'] type

See original GitHub issue
import fetch from "node-fetch";

let f: GlobalFetch["fetch"] = fetch;

This fails with error message:

Type '(url: string | Request, init?: RequestInit) => Promise<Response>' is not assignable to type '(input: RequestInfo, init?: RequestInit) => Promise<Response>'.
  Types of parameters 'url' and 'input' are incompatible.
    Type 'RequestInfo' is not assignable to type 'string | Request'.
      Type 'Request' is not assignable to type 'string | Request'.
        Type 'Request' is not assignable to type 'import("/Users/grant.wu/petuum/api-gateway/node_modules/@types/node-fetch/index").Request'.
          Property 'context' is missing in type 'Request'.

I’m using typescript 3.1.1 and node-fetch 2.2.0.

https://github.com/apollographql/apollo-link/issues/513 this causes problems with code that assumes that GlobalFetch['fetch'] is a good type to represent a generic “fetcher”.

Do you have any suggestions for how to proceed?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bitinncommented, Nov 13, 2018

I saw apollo-env now has a workaround that wrap node-fetch into a fetch with compatible type, I think it’s the right approach, so I am closing this.

0reactions
grantwwucommented, Nov 12, 2019

@cdaringe Nope, didn’t have an alternative to what you came up with in https://github.com/apollographql/apollo-link/issues/513#issuecomment-548219023

Read more comments on GitHub >

github_iconTop Results From Across the Web

fetch's type not matching when calling createHttpLink
Invariant Violation : fetch is not found globally and no fetcher passed, to fix pass a fetch for your environment like https://www.npmjs.com/ ...
Read more >
FetchMode in Hibernate - Baeldung
In this short tutorial, we'll take a look at different FetchMode values we can use in the @org.hibernate.annotations.Fetch annotation.
Read more >
@types/node-fetch - npm
Summary. This package contains type definitions for node-fetch (https://github.com/bitinn/node-fetch). Details.
Read more >
node-fetch | Yarn - Package Manager
A light-weight module that brings Fetch API to Node.js.
Read more >
SQLSTATE values and common error codes - IBM
The position of the cursor referenced in the FETCH statement was after the last row of the ... 42880, The CAST TO and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found