|
|
|
|
|
by dimava
96 days ago
|
|
And then you have a const CatDog = { bark(){}, meow(){} }
and const TreeCat = { bark: "oak", meow(){} }
and your code stops workingTo make types discriminatable you need either type A = { bark: fn, meow?: never } | { bark?: never, meow: fn }
type B = { species: "dog", bark: fn } | { species: "cat", meow: fn }
or use instanceof with a class
|
|