Skip to content

Comment on TypeScript 6.0 RCparent

Comments

And then you have a

    const CatDog = { bark(){}, meow(){} }
and
    const TreeCat = { bark: "oak", meow(){} }
and your code stops working

To 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
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.