interface State1 {
st: number;
}
interface State2 {
tmp1: number;
tmp2: string;
}
const state1: State1 = { st: 1 };
const state2: State2 = { tmp1: 2, tmp2: "3" };
const state = { state1, state2 };
type StateKeys = keyof typeof state;
function getCurrentState(key: StateKeys) {
return state[key];
}
const currentState = getCurrentState("state1");
interface State1 {
st: number;
}
interface State2 {
tmp1: number;
tmp2: string;
}
const state1: State1 = { st: 1 };
const state2: State2 = { tmp1: 2, tmp2: "3" };
const state = { state1, state2 };
function getCurrentState<T extends keyof typeof state>(key: T) {
return state[key];
}
// const currentState1: State1
const currentState1 = getCurrentState("state1");
// const currentState2: State2
const currentState2 = getCurrentState("state2");