Closed

Description
TypeScript Version: 3.1.0-dev.20180818
Code
function sanityCheck(s: string): string {
return s == 0 ? "I must be going insane" : "I'm fine";
}
console.log(sanityCheck(""));
Expected behavior:
Error message is 100% accurate.
Actual behavior:
src/a.ts:2:9 - error TS2367: This condition will always return 'false' since the types 'string' and 'number' have no overlap.
The ==
operator in JavaScript converts its arguments -- some developers apparently rely on this behavior (not naming names but I noticed this in real JavaScript code that I pasted into a TypeScript file).
The error message might recommend using an explicit conversion such as Number(s)
to get this to compile in TypeScript.