0
interface User {name: string, age: Number, fav: {game: string, music: string}}

user: User = {name: 'foo', age: 18, fav: {game: 'action', music: 'classical'}}

function get<?>(key: ?): ? {
    return key.split('.').reduce((a, b) => a[b], user)
}

how to declare it?

type PickByDotNotation<TObject, TPath extends string> =
    TPath extends `${infer TKey extends keyof TObject & string}.${infer TRest}` ?
        PickByDotNotation<TObject[TKey], TRest> :
        TPath extends keyof TObject ?
            TObject[TPath] :
            never

I found it, but not work. i want to

  • 1
    Does this answer your question? [Typescript: deep keyof of a nested object](https://stackoverflow.com/questions/58434389/typescript-deep-keyof-of-a-nested-object) – Teneff Mar 15 '23 at 07:24

0 Answers0