Issue originally discovered by Trevor Schmidt (@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:
Both foo() 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 to foo(), where makeF1p() is called inline, produces a type error at compile time. The second, where the return value of makeF1p() 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:
https://www.typescriptlang.org/play/?ts=3.8.0-dev.20191123&ssl=1&ssc=1&pln=33&pc=1#code/CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPADwBQ858ASgIwA0ZFAYtfCAB4YgrBrwAUASngBeAHxU6DcpQBM9CvEYzWHLj34BLFAAcArhkKUQGXTBQAVAJ7aQRZqKFiqMkqL5Sc1Qs3kVsM7xdHcSgUSxISZHQsbBZhfmD+AG94KEIAcih0+ABfAUjUTBxleL4tPQN4FLT4TBgtAHNcxL4UgCMMtuy8iNwkPljaYqEAehH4AHE8YAioooBbKABrEGYRBJFxWIBuXrw+RZXmQSH-UfGppBmC6PhD1eptdaJzN0rzRJ29-o975m0+Ol0gJfOR-PAxvAAKIwGBIGDwADqAAkAJrwfDuAS7G4LKCgdZ-R6A4E4vruBSLUBDSHmAAWGl4jJwWhAHn8JHyQA
Related Issues: I didn't find any, but Jack Williams (@jack-williams) says #30215 might be the root cause.
Issue originally discovered by Trevor Schmidt (@eyelidlessness) on Gitter.
TypeScript Version: 3.8.0-dev.20191123
Search Terms:
genericreturntypeCode
Expected behavior:
Both
foo()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 to
foo(), 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: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:
https://www.typescriptlang.org/play/?ts=3.8.0-dev.20191123&ssl=1&ssc=1&pln=33&pc=1#code/CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPADwBQ858ASgIwA0ZFAYtfCAB4YgrBrwAUASngBeAHxU6DcpQBM9CvEYzWHLj34BLFAAcArhkKUQGXTBQAVAJ7aQRZqKFiqMkqL5Sc1Qs3kVsM7xdHcSgUSxISZHQsbBZhfmD+AG94KEIAcih0+ABfAUjUTBxleL4tPQN4FLT4TBgtAHNcxL4UgCMMtuy8iNwkPljaYqEAehH4AHE8YAioooBbKABrEGYRBJFxWIBuXrw+RZXmQSH-UfGppBmC6PhD1eptdaJzN0rzRJ29-o975m0+Ol0gJfOR-PAxvAAKIwGBIGDwADqAAkAJrwfDuAS7G4LKCgdZ-R6A4E4vruBSLUBDSHmAAWGl4jJwWhAHn8JHyQA
Related Issues: I didn't find any, but Jack Williams (@jack-williams) says #30215 might be the root cause.