TypeScript Version: 3.5.3
Search Terms:
Code
const num = 1;
function check<T>(x: T) {
return x === num;
}
check(num);
Expected behavior:
No error; check returns true if given num (or an alias of it), and false otherwise.
Actual behavior:
index.ts:3:10 - error TS2367: This condition will always return 'false' since the types 'T' and '1' have no overlap.
3 return x === num;
~~~~~~~~~
Found 1 error.
I observed this in a slightly more complex case but with the same idea:
const makeNum = () => 1;
function check<T>(f: () => T) {
return f === makeNum;
}
check(makeNum);
Playground Link:
https://www.typescriptlang.org/play/#code/MYewdgzgLgBGCuBbGBeGBGA3AKAGbzGCgEtwZgALAU2AGsAeAFQD4AKADwC4ZGBKGAN7YYMAE5Uo8UWBjtUKNAkQ4Avtko1arJb0xA
TypeScript Version: 3.5.3
Search Terms:
Code
Expected behavior:
No error;
checkreturnstrueif givennum(or an alias of it), andfalseotherwise.Actual behavior:
I observed this in a slightly more complex case but with the same idea:
Playground Link:
https://www.typescriptlang.org/play/#code/MYewdgzgLgBGCuBbGBeGBGA3AKAGbzGCgEtwZgALAU2AGsAeAFQD4AKADwC4ZGBKGAN7YYMAE5Uo8UWBjtUKNAkQ4Avtko1arJb0xA