Type Challenges Judge

Type Lookup

提出詳細

type LookUp<U, T> = U extends { type: T } ? U : never
提出日時2023-09-04 14:15:37
問題Type Lookup
ユーザーsnaka
ステータス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>>, ]