-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 2.4.0
Apologies for today's issue raising binge.
Code
// Compiles
const nullCheckOne = (value?: number) => {
if (!!value) {
return value.toFixed(0);
}
return '';
}
const nullCheckTwo = (value?: number) => {
if (Boolean(value)) {
// Object is possibly 'undefined'
return value.toFixed(0);
}
return '';
}
Expected behavior:
Both examples compile.
Actual behavior:
The latter example fails w/ Object is possibly 'undefined'
.
Explanation
To my knowledge !!value
and Boolean(value)
are equivalent. I'm wondering what is the reason behind not supporting the second case. One reason I can think of would be an imported, non-typescript module, globally overriding it to something like: Boolean = (value) => !value
.
esamattis, johngeorgewright, tonivj5, sabberworm, lexek and 91 moreRudxain
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript