3 Matching Annotations
  1. Oct 2019
    1. type FindByTag<Union, Tag> = Union extends { tag: Tag } ? Union : never; function cast<A extends Foo["tag"]>(foo: Foo, expectedTag: A): FindByTag<Foo, A> { if (foo.tag !== expectedTag) throw Error(`expected tag ${expectedTag} but was ${foo.tag}`) return foo as FindByTag<Foo, A>; }