- Notifications
You must be signed in to change notification settings - Fork13.2k
Description
Issue originally discovered by@eyelidlessness on Gitter.
TypeScript Version: 3.8.0-dev.20191123
Search Terms:genericreturntype
Code
declareconstfoo:<R1,F1extends()=>R1,R2,F2extends(input:ReturnType<F1>)=>R2>(f1:F1,f2:F2)=>anyconstf1=()=>({a:'a'})constf2=(input:{a:string})=>({b:'b'})foo(f1,f2)// GoodconstmakeF1=()=>f1;foo(makeF1(),f2)// GoodconstmakeF1p=<T>(t:T)=>f1;foo(makeF1p(''),f2// Error WHY :();constmade=makeF1p('');foo(made,// This is finef2)
Expected behavior:
Bothfoo() calls should compile as the only difference is whether the result of a function call is assigned to a temporary first.
Actual behavior:
The first call tofoo(), wheremakeF1p() is called inline, produces a type error at compile time. The second, where the return value ofmakeF1p() is assigned to temp variable first, compiles fine. The error is:
Argument of type '(input: { a: string; }) => { b: string; }' is not assignable to parameter of type '(input: unknown) => unknown'. Types of parameters 'input' and 'input' are incompatible. Type 'unknown' is not assignable to type '{ a: string; }'.It almost seems like the type parameter inference machinery is leaking outside the scope of the call expression or something? It's weird, at any rate.
Playground Link:
Related Issues: I didn't find any, but@jack-williams says#30215 might be the root cause.