Skip to content

Commit

Permalink
fix(types): use correct version of xstate
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jul 3, 2022
1 parent 296cc6f commit 33409cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ember-statechart-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"peerDependencies": {
"@glint/template": ">= 0.8.3",
"xstate": "^4.30.0"
"xstate": "^4.32.1"
},
"peerDependenciesMeta": {
"@glint/template": {
Expand Down
22 changes: 12 additions & 10 deletions ember-statechart-component/src/glint.ts
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>;
}

0 comments on commit 33409cf

Please sign in to comment.