I have a the following mapper with the type associated with, but I have no clue what to look, to type func
correctly.
type Action<T, K> = {
key: K;
func: // What should this be?
};
type ActionMapper<T> = {
[K in keyof T]: Action<T, K>;
};
export enum EActionSelectPot {
CREATE_ORDER = 'CREATE_ORDER',
ADD_ITEM = 'ADD_ITEM',
DELETE_ORDER = 'DELETE_ORDER',
}
const first_function = () => 'hi';
const second_function = () => ['hi'];
const third_function = () => {
hi: 'hi';
};
const test: ActionMapper<typeof EActionSelectPot> = {
CREATE_ORDER: {
key: EActionSelectPot.CREATE_ORDER,
func: first_function,
},
ADD_ITEM: {
key: EActionSelectPot.ADD_ITEM,
func: second_function,
},
DELETE_ORDER: {
key: EActionSelectPot.DELETE_ORDER,
func: third_function,
},
};
const hi = test.CREATE_ORDER.func();
My goal is pretty straightforward, I have to have an object that infer
the type of the function with generics.
The problem is that I have no clue if this is possible at all, if so, is there any way to accomplish such thing.
I’ve tried with func: () => ReturnType[K]['func']>;
, but I really don’t know where to look for.
I don’t want to infer manually the type of the return, can it be fully dynamic ?
Where to look for ?