-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Recent --strictNullChecks issue w/ && || type result check #9113
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
Comments
1 more example: function sq(n?: number): number {
const r = n !== undefined && n*n || 0;
return r;
}
alert(sq(3)); sq.ts(3,9): error TS2322: Type 'number | boolean' is not assignable to type 'number'. |
I see what's going on here. The issue is that we give the sub-expression Then we should furthermore say that in an Now, the only problem with this solution is that we don't (yet) support boolean literal types or numeric literal types. This means we need to do one of the following:
Adding @mhegazy and @RyanCavanaugh. |
👍 |
and numeric ranges:
|
Numeric ranges? Are those even possible? That'd be über cool though. |
About 1 weak ago, this sample below would transpile flawlessly under --strictNullChecks:
But to my surprise today, under [email protected], only the statement using the ternary conditional operator works now!
Somehow TS thinks that choice could be
boolean
as well when using&&
+||
expression. =(Is that intentional from now on? I miss when it was smarter just 1 week ago. :-(
tsc --pretty --newLine LF --removeComments --experimentalDecorators --strictNullChecks -d -t ES6 sinCos
The text was updated successfully, but these errors were encountered: