There are a number of resources on how to do deep property access in a type-safe way. In my application, though, I need to pass around the property key ('a.b.c'
) as a sort of unique key into the data. I'm not sure how to translate some of those ideas to my case:
type Pizza = {
sauce: string
cheese: {
name: string
stinkiness: number
}
}
function torgle<R extends Record<string, any>>(
records: R[], key: keyof R | ???
) { ... }
torgle(pizzas, 'sauce')
torgle(pizzas, 'cheese.stinkiness')
In the latest Typescript, is there any type better than string
that could substitute for ???
here?