3 ms·
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/C4TwDgpgBAIg9g
by culi 8mo ago
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/C4TwDgpgBAIg9gcygXigbygIwIYCcDWAXFABQCUKAfFAG5wCWAJlAL4BQokUAwtsCuigBbCHADuxclVoNm7NgDMArgDsAxsHpwVUAM6Rs+EthX0h2ADbF4SAD48+FNGyiuo9BaQBEOAl-c6JmaWTi5u4UHmFgB0vkZkANxh4a4A9KlQAHoA-MmsUBAWutDOKW6RltEi4uRJZWkZOXnsLEA https://www.typescriptlang.org/play/?#code/C4TwDgpgBAIg9gcyg...
- Incipient 8mo agoThe 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.html#instanceof-narrowing https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...
- culi 8mo agoI 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/Reference/Operators/instanceof https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...