-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Description
Search Terms:
!=, implicit conversion
Code
const x = 0;
const y = '0';
if (x != y) {
console.log('In if block');
} else {
console.log('In else block');
}Expected behavior:
The code should compile successfully. Since != uses implicit conversion it is possible for 'x != y' to be false even if x is a number and y is a string. For example 0 != '0' is false).
Note that when the javascript file generated by tsc in the above code is run, the else block is hit as expected.
Actual behavior:
The code has the compilation error:
error TS2367: This condition will always return 'true' since the types 'number' and 'string' have no overlap.
5 if (x != y) {
~~~~~~
Playground Link:
Related Issues:
No
Metadata
Metadata
Assignees
Labels
Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it