-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 3.4.5
Search Terms: union type inference conjunction strictNullChecks
Code
function fn(x: number) {
return x && 'a'
}
Expected behavior:
Return type of fn
should be 0 | 'a'
Actual behavior:
Return type of fn
is '' | 'a'
if strictNullChecks
is disabled
This is causing me an issue with this specific bit of code, where I'm checking window
so my code runs both on the browser and on the client:
function fn(x: number): OrientationType | undefined {
return window && (window.outerWidth > window.outerHeight ? 'landscape-primary' : 'portrait-primary')
}
I can replace the conjunction with a conditional expression, and I know that if strictNullChecks
is disabled I should have a fallback for the return value but I'm posting here for the sake of trying to understand if this is working as intended. It also feels weird that my example compiles with strictNullChecks
enabled but doesn't compile when it's disabled.
Related Issues:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript