Seeking a method for implementing general type checking on the keys of an object and its children. Here is the concept:
type A<T> = {
key: keyof T;
childKey: keyof T[this.key] // struggling to implement this part
};
If the above type is functional, it would be utilized in scenarios like:
const a = { child1: { param: 1 }, child2: { param: 1 } };
const myObj: A<typeof a> = {
key: "child3", // << 'child3' is not a key of object 'a'
childKey: "param"
}
const myObj: A<typeof a> = {
key: "child1",
childKey: "param2" // << 'param2' is not a key of 'a.child1'
}
I have attempted using keyof T[this.key]
, keyof T["key"]
, keyof ThisType["key]
, but none of them provide the desired results. Any suggestions or guidance would be greatly appreciated.