Type Challenges Judge

Typed Get

提出詳細

type Get<T, K> = K extends keyof T ? T[K] : K extends `${infer K1}.${infer K2}` ? K1 extends keyof T ? Get<T[K1], K2> : never : never
提出日時2023-09-20 01:55:13
問題Typed Get
ユーザーsankantsu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Get<Data, 'hello'>, 'world'>>, Expect<Equal<Get<Data, 'foo.bar.count'>, 6>>, Expect<Equal<Get<Data, 'foo.bar'>, { value: 'foobar'; count: 6 }>>, Expect<Equal<Get<Data, 'no.existed'>, never>>, ] type Data = { foo: { bar: { value: 'foobar' count: 6 } included: true } hello: 'world' }