Closed
Description
TypeScript Version: 2.8.0-dev.20180315
Search Terms:
infer conditional generic function
Code
type Id = <T>(item: T) => T;
type X = ((t: Id) => void) extends (t: (item: any) => any) => void ? "yes" : "no";
// Resolves to "yes", as expected
type Y = ((t: Id) => void) extends (t: (item: any) => infer R) => void ? "yes" : "no";
// Resolves to "no", but "yes" is desired
The code checks whether a function that takes the identity function is assignable to a function that takes some function any => any
. This is clearly assignable, and thus results in "yes". However, when replacing one any
by infer R
, the other branch is taken. I think that replacing any
by an infer R
type should never change the branch that is taken.
{
"compilerOptions": {
"allowJs": true,
"target": "es6",
"module": "commonjs",
"outDir": "dest",
"strictNullChecks": true,
"jsx": "preserve",
"strictFunctionTypes": true
}
}
Expected behavior:
X
and Y
resolve to "yes"
Actual behavior:
Y
resolves to "no"
Related Issues: