Type Lookup
提出詳細
type LookUp<U extends { type: string }, T extends string> = U extends { type: T } ? U:never;
提出日時 | 2022-06-27 11:59:08 |
---|---|
問題 | Type Lookup |
ユーザー | waki285 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' interface Cat { type: 'cat' breeds: 'Abyssinian' | 'Shorthair' | 'Curl' | 'Bengal' } interface Dog { type: 'dog' breeds: 'Hound' | 'Brittany' | 'Bulldog' | 'Boxer' color: 'brown' | 'white' | 'black' } type Animal = Cat | Dog type cases = [ Expect<Equal<LookUp<Animal, 'dog'>, Dog>>, Expect<Equal<LookUp<Animal, 'cat'>, Cat>>, ]