You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript already detects comparisons that will always be false because the types have no overlap.
However, it doesn't detect the opposite: if a comparison of literal types will always be true.
Related upstream feature request: microsoft/TypeScript#28569
declarefunctionget<T>(): T;'a'==='a';// always true'a'=='a';// always true'a'!=='a';// always false'a'==='b';// compiler already errors here'a'!=='b';// compiler already errors here'0'==0;// compiler already errors hereget<'a'|'b'>()==='a';// validget<'a'|'b'>()===get<'a'|'b'>();// validget<string>===get<string>();// valid// advanced'0'==get<'0'|0>();// always true'0'==get<'0'|1>();// valid// should be handled by a different ruleleta: string;a===a;
The same applies to switch although that should be rather rare.
When microsoft/TypeScript#26592 is fixed upstream, there might be the need for an additional check for loose equal with values of a different type, e.g. '0' == 0.
The text was updated successfully, but these errors were encountered:
TypeScript already detects comparisons that will always be false because the types have no overlap.
However, it doesn't detect the opposite: if a comparison of literal types will always be true.
Related upstream feature request: microsoft/TypeScript#28569
The same applies to
switch
although that should be rather rare.When microsoft/TypeScript#26592 is fixed upstream, there might be the need for an additional check for loose equal with values of a different type, e.g.
'0' == 0
.The text was updated successfully, but these errors were encountered: