TypeScript Version: 2.4.0
Apologies for today's issue raising binge.
Code
// CompilesconstnullCheckOne=(value?: number)=>{if(!!value){returnvalue.toFixed(0);}return'';}constnullCheckTwo=(value?: number)=>{if(Boolean(value)){// Object is possibly 'undefined'returnvalue.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.
TypeScript Version: 2.4.0
Apologies for today's issue raising binge.
Code
Expected behavior:
Both examples compile.
Actual behavior:
The latter example fails w/
Object is possibly 'undefined'.Explanation
To my knowledge
!!valueandBoolean(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.