-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat Boolean(x)
equally as double not !!x
#37180
Comments
i think your issue may couldnot be sensed by when the parameter of Boolean is another function's parameter, like this: function xxx(a?: A) {
return Boolean(a) && a.a; // the compiler cannot helps you to understanding this case
} |
@Ezio1212 I am not sure I follow your suggestion, can you elaborate?
expressions work exactly the same way in context of a function as they work outside - |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
In complex boolean expressions it's clearer to do
Boolean(x)
cast rather than!!x
in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy to mistype!
. Typescript should treatBoolean(x)
the same way as!!
.TypeScript Version: 3.6.3,3.7.5,3.8.3 (tried top 3 available in playground)
Search Terms:
boolean cast non null
double negation boolean cast
double not Boolean
Code
Expected behavior:
Boolean(x)
should be treated as equivalent of!!x
Actual behavior:
Using
Boolean
as a function does not contribute to TS understanding of object existensePlayground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=9&pc=31#code/JYOwLgpgTgZghgYwgAgILIN4Chm+XALmRAFcBbAI2iwF8ssEB7EAZzHyPQB9kSQATCDFAR+9Jq0YAbCADopjAOYAKOMgBk6-AH5ZcAJQNmLaXIUqAhBbWb8ewxJMz5S5QCFGpuCFX6NWuHsgA
Related Issues:
The text was updated successfully, but these errors were encountered: