type Dog = { bark(): void; type: 'dog' } type Cat = { meow(): void; type: 'cat' } function speak(animal: Dog | Cat) { if (animal.type === 'dog') { animal.bark() } else { animal.meow() } }
TypeScript checks your use of JavaScript runtime features.
[1] https://www.convex.dev/typescript/advanced/type-operators-ma...
TypeScript checks your use of JavaScript runtime features.
[1] https://www.convex.dev/typescript/advanced/type-operators-ma...