Best practice for typing dynamic machine configs #5104
Unanswered
AlexZasorin
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I found these two exported type while looking for a generic // xstate type definitions
export type UnknownMachineConfig = MachineConfig<MachineContext, EventObject>;
export type AnyStateMachine = StateMachine<any, // context
any, // event
any, // children
any, // actor
any, // action
any, // guard
any, // delay
any, // state value
any, // tag
any, // input
any, // output
any, // emitted
any, // TMeta
any>; With the following import: import { AnyStateMachine, UnknownMachineConfig } from 'xstate'; However, I'm not sure this is relevant since there's no typing inference... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently working on a project where I'm storing machine configs in a database. These machines can take any form so we don't know what states or events they may have. I'm currently working on trying to improve the typing for these configs and would like to ask what the best practice for this is.
I'm looking for a generic machine config type to use for typing the input and return data for my database, as well as my test fixtures. I attempted to use
UnknownMachineConfig
, but passing in something typed asUnknownMachineConfig
tocreateMachine
gives a TypeScript error.createMachine
seems to not acceptparams
in ParamterizedObject andid
in ProvidedActor being potentially undefined. I've gotten around this with:I'm not sure why I had to do this and it gives me the feeling that I'm approaching this wrong. Any advice?
Beta Was this translation helpful? Give feedback.
All reactions