Comment by culi
4 hours ago
You don't even need that. The code exactly as presented acts as a discriminator. TypeScript is smart enough to handle that logic in the if block and know whether animal has been validated as Dog vs Cat. GP is complaining about a feature that already exists in TypeScript
It depends how you construct Dog and Cat. With Javascripts dynamic prototype chain, you could never know for sure.
Try it
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAIg9gcyg...
type Mutt = Dog & Cat
const imposter: Mutt = { bark: () => console.log("woof"), meow: () => console.log("meow"), }
You're both misunderstanding parent's point as well as the original point. Nobody ever claimed your link wouldn't compile.
1 reply →