Reputation: 7640
let's say I have this ternary
control.value ? null : { invalid: true };
I want value to be valid if it's anything BUT null
undefined
and ""
Now 0
is a valid value.
I know there is a nullish coalescing operator in typescript ??
but it is not usable in ternary.
so How would I make this line simple ? Is there a syntax better than control.value === 0 || control.value ? null : { invalid: true };
to consider 0 as valid ?
Upvotes: 1
Views: 491
Reputation: 159
Hopefully this helps you:
value ? null: value === 0 ? null : { invalid: true }
Upvotes: 1