javascript - Typescript if and if not with boolean and string -
i editing app using typescript react , meteor. got following state:
{user && ( ... )} this shows data if visitor logged in user. although want show data only if tournament not cancelled. tried add
{user && !tournament.state === 'cancelled' && ( ... )} which not work. receive following linter message:
operator '===' cannot applied types 'boolean' , '"cancelled"'.
how can solve puzzle?
typescript complains because trying compare boolean value: !tournament.state string: 'cancelled'.
the ! symbol going turn truthy/falsy result boolean. happens because assuming tournament.state equal 'cancelled':
!tournament.state = !'cancelled' = false the triple equals operator checks both value , type. code not disliked typescript, incorrect, every value of tournament.state going fail check, because end boolean against string. need is:
{user && tournament.state !== 'cancelled' && ( ... )}
Comments
Post a Comment