3 Matching Annotations
- Oct 2019
-
stackoverflow.com stackoverflow.com
-
type A = string extends keyof Person["favouriteNumbers"] ? true : false; // true
-
-
github.com github.com
-
function foo<T extends string | number>(val: T): T extends string ? string : number {
-
-
github.com github.com
-
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>; }
-