Type Challenges Judge

Typed Get

提出詳細

type Get<T, K> = K extends `${infer A}.${infer B}` ? A extends keyof T ? Get<T[A], B> : never : K extends keyof T ? T[K] : never;
提出日時2023-08-09 11:00:59
問題Typed Get
ユーザーookkoouu
ステータス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' }