Comment

Comment by littlecranky67

Typeguard is what you are looking for: function isDog(animal: Dog | Cat): animal is Dog { return "bark" in Dog }

Then: isDog(animal) ? animal.bark() : animal.meow() You get full type narrowing inside conditionals using typeguards.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton