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()?
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;}
Activity
lll000111 commentedon Jul 8, 2019
Okay... so I found that the order of the individual tests matters, which is just as strange so I see no reason to close the issue.
Playground link
jack-williams commentedon Jul 8, 2019
Duplicate of #28131