|
|
|
|
|
by littlecranky67
101 days ago
|
|
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. |
|