I have a trouble with Typescript I am trying to infer the properties of an Object dynamically.
take a look at the below code
const Actions = {
globalUI: {
openModal: 'openModal'
}
}
type Param = keyof typeof Actions;
type T = <T, K extends keyof T>(action: T, key: K) => T[K];
const fn = (param: Param) => {
const action = mapper(Actions, param);
return action
}
const mapper:T = (action, name) => {
return action[name]
}
const action = fn('globalUI');
as you can see Typescript can infer a global UI properties
but When I put the additional property in the Actions Object

Typescript doesn't infer Object properties
const Actions = {
globalUI: {
openModal: 'openModal'
},
LP: {
addDirectory: 'addDirectory'
}
}
type Param = keyof typeof Actions;
type T = <T, K extends keyof T>(action: T, key: K) => T[K];
const fn = (param: Param) => {
const action = mapper(Actions, param);
return action
}
const mapper:T = (action, name) => {
return action[name]
}
const action = fn('globalUI');
How can I achieve it? please give any idea

