I have the following types:
interface CellsReducer {
source: number;
destination: number;
plan: string;
duration: number;
test: []
}
interface BarReducer {
baz: string;
}
interface AppState {
cells: CellsReducer;
bar: BarReducer;
}
I want to write an interface with the following objects:
interface Props {
store: keyof AppState;
field: // AppState[store]
data: // AppState[store][field]
}
Using Generics didn't get me anywhere. fields ends up with type never in the following example:
type Stores<T> = keyof T;
type Fields<T> = keyof T[Stores<T>];
type Props<TState> = {
state: Stores<TState>;
field: Fields<TState>
}
Is there a way of doing this?