I have following function:
function doSomething(param1: string, param2: string) {
return param1 + param2;
}
also I have json based type with structure looking similar to this:
a1: {
b1: 'something1',
b2: 'something2',
b3: 'something3'
},
a2: {
c1: 'something4',
c2: 'something5'
}
...etc
I want nth argument of mentioned function to be literal of nth deep elements, so if first argument is 'a1', second should be 'b1' | 'b2' | 'b3', and if first argument is 'a2', second should be 'c1' | 'c2'.
For first argument I've made simple keyof typeof data type, which is working great:
// data is imported json
type FirstArg = keyof typeof data;
For second I was trying generic type like this, but without success:
type SecondArg<T extends FirstArg> = keyof typeof data[T];
Any chance to do that?