Type Challenges Judge

Type Lookup

提出詳細

type LookUp<U, T> = U extends { type: T } ? U : never
提出日時2022-07-16 06:03:22
問題Type Lookup
ユーザーaa-0921
ステータス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>>, ]