Open vasilii-kovalev opened 4 years ago
it's works if use dataItem.field === undefined || dataItem.field === false
instead of !Boolean(dataItem.field)
@ikabirov, thanks for your example! Is it a common and expected practice to clarify the condition in such way to make strong typing work or it is just a temporal workaround?
Explicit is better than implicit. By it's just my opinion. cc @JSMonk
for me x === true
or x !== true
is very good way to convert any value to boolean
everything that's not true will become false (it matches Boolean
constructors behavior for undefined and null but not for strings and numbers or arrays etc)
if you want true
for everything that's not boolean you can use x !== false
or x === false
function foo(value: ?boolean): boolean {
if (value !== true) {
return false
}
return value
}
Thank you a lot for your contribution ^_^. I will fix it soon.
It's actually hard to describe the problem in the title in couple of words. You can find the playground here.
true
in "else" part since we already handlefalse
in "if" part.field
(on the top level of theresult
object) istrue
andfield
's type insideonClick
function isboolean | undefined
, but in the Hegel exemple both fields haveboolean | undefined
type. Which behavior is more correct?