I am trying to make a request using node-fetch
in my typescript project and I do not understand how to fix the compilation error or what it actually tries to tell me.
I've updated all packages (including the global typescript package) to the latest versions.
I've created a gist that isolates the error: https://gist.github.com/HerrZatacke/ae90f608e042864b6e00e9c73a950602
This (very short) script is able to reproduce the compilation error:
import fetch from 'node-fetch';
const toJson = (response: Response):PromiseLike<object> => (
response.json()
);
const makeSomeRequest = (): Promise<object> => {
return fetch('https://some-api.com/')
.then(toJson)
};
makeSomeRequest();
The installed versions used are
@types/node-fetch 2.3.7
node-fetch2.6.0
typescript 3.5.2
the actual error is
example.ts:9:11 - error TS2345: Argument of type '(response: Response) => PromiseLike<object>' is not assignable to parameter of type '(value: Response) => object | PromiseLike<object>'.
Types of parameters 'response' and 'value' are incompatible.
Type 'Response' is missing the following properties from type 'Response': redirected, trailer, formData