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
{{ message }}
Repository navigation
Inequality comparison with string literal shows editor error #14983
I think this is a bug. I might be wrong. TypeScript Version: 2.2.1
Code
classGreeter{greeting: string;constructor(message: string){if(message!=='world'||message!=='me'){// do something}this.greeting=message;}greet(){return"Hello, "+this.greeting;}}
Expected behavior:
I am trying this on typescript playground, it should show no error in the editor. Actual behavior:
The second condition in the if statement is underlined. The error message is
Operator '!==' cannot be applied to types '"world"' and '"me"'.
Same thing happened in Visual studio code with Typescript 2.2.1
Activity
RyanCavanaugh commentedon Apr 3, 2017
The condition you have here
always evaluates to
true.Perhaps you meant to write
or
yiochen commentedon Apr 3, 2017
Oh, it's because of that. I wish the error message was more intuitive. But thanks, I'm going to close this issue.