You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiondemoV1(thing: unknown): void{if(thing===null||typeofthing!=='object'){thrownewError('not an object');}// ERROR: thing is object || nullconstobj: object=thing;}functiondemoV2(thing: unknown): void{if(typeofthing!=='object'){thrownewError('not an object');}if(thing===null){thrownewError('not an object');}// WORKSconstobj: object=thing;}
So... TypeScript does not understand an or operator "||" to test twp things in the same if()?
The text was updated successfully, but these errors were encountered:
functiondemoV1(thing: unknown): void{if(typeofthing!=='object'||thing===null){thrownewError('not an object');}// WORKSconstobj: object=thing;}functiondemoV2(thing: unknown): void{if(thing===null){thrownewError('not an object');}if(typeofthing!=='object'){thrownewError('not an object');}// ERROR: thing is object || nullconstobj: object=thing;}
I created a few tiny examples, one per demo function:
Playground link
In particular, these two:
So... TypeScript does not understand an or operator "||" to test twp things in the same
if()
?The text was updated successfully, but these errors were encountered: