Comment on TypeScript 6.0 RCparentComments−culi6moYour first code block works exactly as you would expect and has been working like that for many yearshttps://www.typescriptlang.org/play/?#code/C4TwDgpgBAIg9gcyg...−Incipient6moThe op did say they didn't want to do these type of checks.I thought the answer was 'instanceof'?https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...−culi6moI see what you mean, thanks. instanceof works if you're using javascript classes but not for "types".You can't do `instanceof Dog`. `instanceof` is a JavaScript featurehttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Comments
Your first code block works exactly as you would expect and has been working like that for many years
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAIg9gcyg...
The op did say they didn't want to do these type of checks.
I thought the answer was 'instanceof'?
https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...
I see what you mean, thanks. instanceof works if you're using javascript classes but not for "types".
You can't do `instanceof Dog`. `instanceof` is a JavaScript feature
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...