diff --git a/src/index.tsx b/src/index.tsx index 763c201..ef90fa5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,7 +7,7 @@ type Transition = guard?: (context: C) => boolean; }; -type KeysOfTransition = Obj extends Record> ? keyof Obj : never; +type KeysOfTransition = Obj extends { on: { [key: string]: Transition } } ? keyof Obj['on'] : never; interface BaseStateConfig { on?: { @@ -22,8 +22,6 @@ interface BaseConfig { }; } -type TransitionEvent>> = T[keyof T]['on']; - type ContextUpdater = (updater: (context: C) => C) => void; interface MachineStateConfig extends BaseStateConfig { @@ -46,7 +44,7 @@ const getReducer = < Context extends Record, Config extends BaseConfig, State extends keyof Config['states'], - Event extends KeysOfTransition> + Event extends KeysOfTransition >( config: Config ) => @@ -100,7 +98,7 @@ export default function useStateMachine return function useStateMachineWithContext>(config: Config) { type IndexableState = keyof typeof config.states; type State = keyof Config['states']; - type Event = KeysOfTransition>; + type Event = KeysOfTransition; const initialState = useConstant(() => ({ value: config.initial as State,