Skip to content

Commit

Permalink
Merge pull request #2102 from VanTanev/interpreter-from-infer-type
Browse files Browse the repository at this point in the history
Provide convenience type InterpreterFrom<typeof machine>
  • Loading branch information
davidkpiano committed Apr 16, 2021
2 parents 14cdef6 + 25d93b5 commit 7eaad96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-owls-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Provide a convenience type for getting the `Interpreter` type based on the `StateMachine` type by transferring all generic parameters onto it. It can be used like this: `InterpreterFrom<typeof machine>`
11 changes: 11 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,14 @@ export type ActorRefFrom<
: never;

export type AnyInterpreter = Interpreter<any, any, any, any>;

export type InterpreterFrom<
T extends StateMachine<any, any, any, any>
> = T extends StateMachine<
infer TContext,
infer TStateSchema,
infer TEvent,
infer TTypestate
>
? Interpreter<TContext, TStateSchema, TEvent, TTypestate>
: never;

0 comments on commit 7eaad96

Please sign in to comment.