Closed xenjke closed 3 years ago
3.1.2 is still failing:
tsc --lib 'es2015,dom' response-compatibility.ts
response-compatibility.ts:3:35 - error TS2345: Argument of type '(response: Response) => Response' is not assignable to parameter of type '(value: Response) => Response | PromiseLike<Response>'.
Types of parameters 'response' and 'value' are incompatible.
Type 'import("/Users/ashulzhe/workspace/fetch_repro/node_modules/cross-fetch/lib.fetch").Response' is not assignable to type 'Response'.
The types returned by 'body.getReader(...).read(...)' are incompatible between these types.
Type 'Promise<ReadableStreamDefaultReadResult<Uint8Array>>' is not assignable to type 'Promise<ReadableStreamReadResult<T>>'.
Type 'ReadableStreamDefaultReadResult<Uint8Array>' is not assignable to type 'ReadableStreamReadResult<T>'.
Type 'ReadableStreamDefaultReadValueResult<Uint8Array>' is not assignable to type 'ReadableStreamReadResult<T>'.
Type 'ReadableStreamDefaultReadValueResult<Uint8Array>' is not assignable to type 'ReadableStreamReadValueResult<T>'.
Types of property 'value' are incompatible.
Type 'Uint8Array' is not assignable to type 'T'.
'Uint8Array' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'ArrayBufferView'.
3 fetch('https://www.example').then((response: Response) => {
~~~~~~~~~~~~~~~~~~~~~~~~~
Oh, just saw this line. Looks like those types are from later version of TypeScript.
Tried running with TS 4.2.3:
> node_modules/.bin/tsc -v
Version 4.2.3
> node_modules/.bin/tsc --lib 'dom,es2015' response-compatibility.ts
# compiles!
@xenjke hey, thanks for reporting this issue. Can you run npm install cross-fetch@3.1.3-alpha.6
and check if the problem persists?
Hey @lquixada, thank you for the quick turnaround! I can confirm that cross-fetch@3.1.3-alpha.6
resolved the issue for us. We'll pick the fix up from the release 👍
Issue
Version 3.1.0 introduced a breaking change to
Response
type.Up to this version, Cross-Fetch response type was matching
Response
type from TypeScript TypesExample code
Compilation failure
Same example compiles fine with
cross-fetch
locked to 3.0.6.Environment