@@ -12,28 +12,28 @@ export type StatemachineTransitions<States extends TStates> = {
1212
1313export interface MachineMethods < States extends TStates > {
1414 reset : ( ) => void
15- matches < T extends States [ "state" ] [ ] > ( ...states : T ) : this is Statemachine < States > & ( States extends {
15+ matches < T extends States [ "state" ] [ ] > ( ...states : T ) : this is Statemachine < States , States extends {
1616 state : T extends Array < infer S > ? S : never ;
17- } ? States : never ) ;
18- transition < State extends States [ "state" ] , > (
17+ } ? States : never > ;
18+ transition < State extends States [ "state" ] > (
1919 state : State ,
20- entry ?: ( current : Statemachine < States > & ( States extends { state : State } ? States : never ) ) => void ,
21- exit ?: ( current : Statemachine < States > & ( States extends { state : State } ? States : never ) ) => void
20+ entry ?: ( current : Statemachine < States , States extends { state : State } ? States : never > ) => void ,
21+ exit ?: ( current : Statemachine < States , States extends { state : State } ? States : never > ) => void
2222 ) : Promise < void >
2323 whenTransitioned : ( state : States [ "state" ] ) => Promise < void >
2424}
2525
26- export type Statemachine < States extends TStates > = States & MachineMethods < States >
26+ export type Statemachine < States extends TStates , State extends TStates = States > = State & MachineMethods < States >
2727
2828const CURRENT_EXIT = Symbol ( 'CURRENT_EXIT' )
2929const INITIAL_STATE = Symbol ( 'INITIAL_STATE' )
3030const TRANSITIONS = Symbol ( 'TRANSITIONS' )
3131const PENDING_TRANSITIONS = Symbol ( 'PENDING_TRANSITIONS' )
3232
33- class StateMachine < States extends TStates > {
34- state : States [ "state" ]
33+ class StateMachine < States extends TStates , State extends TStates = States > {
34+ state : State [ "state" ]
3535 private [ CURRENT_EXIT ] : ( ( ) => void ) | undefined
36- private [ INITIAL_STATE ] : States [ "state" ]
36+ private [ INITIAL_STATE ] : State [ "state" ]
3737 private [ PENDING_TRANSITIONS ] : { [ key : string ] : Function [ ] } = { }
3838 constructor ( transitions : StatemachineTransitions < States > , definition : States ) {
3939 this [ INITIAL_STATE ] = definition . state
0 commit comments