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