I want to get a union of all the keys under on in this object type inferred from a configuration object:
type Config = {
initial: string;
states: {
idle: {
on: {
START: string;
};
effect(): void;
};
running: {
on: {
PAUSE: string;
};
effect(): void;
};
paused: {
initial: string;
states: {
frozen: {
on: {
HEAT: string;
};
};
};
on: {
RESET: string;
};
};
};
}
Note that the configuration can have nested on keys under states. Right now I can get the first level keys using:
type KeysOfTransition<Obj> = Obj extends Record<PropertyKey, any> ? keyof Obj : never;
type TransitionKeys = KeysOfTransition<Config["states"][keyof Config["states"]]["on"]>
// "START" | "PAUSE" | "RESET"
But I cannot get HEAT in the union, which is nested. Any ideas?
onalways under the second lvstates?