I'm trying to infer the parameters of a nested object that looks like this:
const lightSwitch = {
off: {
switchOn: (state: Data, payload: number) => ({
...state,
state: 'on',
meta: payload,
}),
},
on: {
switchOff: (state: Data) => ({
...state,
state: 'off',
}),
},
};
I want a type, Params
, that looks like this:
{
'switchOn': [state: Data, payload: number]
'switchOff': [state: Data]
}
Here's what I'm doing:
type Intersect<T> = T extends { [K in keyof T]: infer E } ? E : T;
type Flattened = Intersect<typeof lightSwitch>;
type Params = { [K in keyof Flattened]: Parameters<Flattened[K]> }; // type Params = {}
Why is Params
empty, and how do I correct this?