This works fine for mapping deep keys of objects:
type Car = {
color: string;
model: {
name: string;
}
}
export type DeepKey<T> = {
[P in keyof T]: DeepKey<T[P]>;
}
const car: DeepKey<Car> = {};
car.model.name // is ok
But how to make it a chain of functions like this:
car("model")("name")
Something like:
export type DeepFunc<T> = (k: [P in keyof T]) => DeepFunc<T[P]>;
Another solution could be maybe array of keys like this. (But the function way is interesting too)
["model", "name"] or ["color"]
DeepKey<Car>, vs. just usingCar? And in the latter example, how is that actually implemented at runtime, let alone in typing, how does it know when you want the actual value rather than a wrapper function for the next layer?pathin ramda?