-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.8.0-dev.20200115
Search Terms: overlap boolean vs array condition
Code
function isAllowed() {
const myCondition = false;
if (myCondition === false) {
return [];
}
return true;
}
if (isAllowed()) {
// boolean and array will results in a "true" condition
console.log('allowed');
} else {
// never reached
console.log('not allowed');
}Expected behavior:
- Seeing a message saying something like
This condition can produce unexpected results since the types 'boolean' and 'array' have no overlap(not really good but you get the idea)
Actual behavior:
I won't say that it's a bug, but something that could be improved. I know that it's valid javascript but this a bug in the code that should/could be prevented by Typescript
- Typescript does not complain that comparing boolean and array can results in bad condition
Already fixable by
- It does complain if you write
if (isAllowed() === true)but it's easy to not do it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript