-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): use correct version of xstate
- Loading branch information
1 parent
296cc6f
commit 33409cf
Showing
2 changed files
with
13 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { ComponentLike } from '@glint/template'; | ||
import type { | ||
AnyStateMachine, | ||
ContextFrom, | ||
createMachine, | ||
EventFrom, | ||
Interpreter, | ||
MachineConfig, | ||
StateFrom, | ||
StateMachine, | ||
StateSchema, | ||
} from 'xstate'; | ||
|
||
type StateSchemaFrom<T> = T extends StateMachine<any, infer U, any> ? U : StateSchema; | ||
|
||
export type State<T = unknown> = Interpreter<ContextFrom<T>>['state']; | ||
export type Send<T = unknown> = Interpreter<ContextFrom<T>>['send']; | ||
export type OnTransition<T = unknown> = Interpreter<ContextFrom<T>>['onTransition']; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type MachineComponent<T extends ReturnType<typeof createMachine> = any> = ComponentLike<{ | ||
export type MachineComponent<T extends AnyStateMachine = any> = ComponentLike<{ | ||
Args: { | ||
config?: MachineConfig<ContextFrom<T>, StateSchema<T>, EventFrom<T>>; | ||
context?: State<T>['context']; | ||
state?: State<T>; | ||
config?: MachineConfig<ContextFrom<T>, StateSchemaFrom<T>, EventFrom<T>>; | ||
context?: StateFrom<T>['context']; | ||
state?: StateFrom<T>; | ||
}; | ||
Blocks: { | ||
default: [State<T>, Send<T>, OnTransition<T>]; | ||
}; | ||
}>; | ||
|
||
export function asComponent<T extends typeof createMachine>( | ||
machine: T | ||
): MachineComponent<ReturnType<T>> { | ||
return machine as unknown as MachineComponent<ReturnType<T>>; | ||
export function asComponent<T extends AnyStateMachine = any>(machine: T): MachineComponent<T> { | ||
return machine as unknown as MachineComponent<T>; | ||
} |