Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.3k
Best practice for typing dynamic machine configs#5104
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 // Makes the selected keys requiredexporttypePickRequired<T,KextendskeyofT>=Omit<T,K>&Required<Pick<T,K>>;// Stricter version of these two xstate types because `createMachine()` expects `params` to be required inside of// ParameterizedObject and `id` to be required inside of `ProvidedActor`exporttypeStrictParameterizedObject=PickRequired<ParameterizedObject,'params'>;exporttypeStrictProvidedActor=PickRequired<ProvidedActor,'id'>;exporttypeGenericMachineConfig=MachineConfig<MachineContext,EventObject,StrictProvidedActor,StrictParameterizedObject,StrictParameterizedObject,string,string,any,unknown,EventObject,MetaObject>; I'm not sure why I had to do this and it gives me the feeling that I'm approaching this wrong. Any advice? |
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
Replies: 1 comment 1 reply
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 found these two exported type while looking for a generic // xstate type definitionsexporttypeUnknownMachineConfig=MachineConfig<MachineContext,EventObject>;exporttypeAnyStateMachine=StateMachine<any,// contextany,// eventany,// childrenany,// actorany,// actionany,// guardany,// delayany,// state valueany,// tagany,// inputany,// outputany,// emittedany,// TMetaany>; With the following import: import{AnyStateMachine,UnknownMachineConfig}from'xstate'; However, I'm not sure this is relevant since there's no typing inference... |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
-
Thanks@RemyMachado I was struggling building a service capable to operate xstate state machines, something like strategy pattern using machines like strategies. With typescript it was very difficult to define a generic type for every xstate state machine. |
BetaWas this translation helpful?Give feedback.