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
// A *self-contained* demonstration of the problem follows...lets:string=(""&&false);
Expected behavior:
Since ("" && false) is "" in JavaScript I should be able to assign the resulting value to a string, but TypeScript thinks that this will become a boolean. Actual behavior:
Compiler error claiming that a boolean cannot be assigned to a string
Disclaimer: I think that the behaviour of the && operator in JavaScript is horrible, however it is what it is and TypeScript should honour it.
The text was updated successfully, but these errors were encountered:
RyanCavanaough: This was found when turning on strictNullChecks on an existing codebase, not the example that I showed of course, that was just a simplification to be clear.
We had complex logical expressions with && that relied on returning a string. They could have returned other types too, but we did not handle that, so to understand what was going on and to fix the code, we started to read up on the && operator and what it returns in different circumstances, then we tried those circumstances out in TypeScript and found the error reported here.
TypeScript Version: 2.0.8
Code
Expected behavior:
Since ("" && false) is "" in JavaScript I should be able to assign the resulting value to a string, but TypeScript thinks that this will become a boolean.
Actual behavior:
Compiler error claiming that a boolean cannot be assigned to a string
Disclaimer: I think that the behaviour of the && operator in JavaScript is horrible, however it is what it is and TypeScript should honour it.
The text was updated successfully, but these errors were encountered: