How to extract invoke call into it's own TypeSafe method #5240
Answered
by
davidkpiano
CodenameLiam
asked this question in
Q&A
-
Lets safe I have a machine like this const machine = setup({
actors: {
processDeviceLogin: fromPromise<DeviceLoginResponse, DeviceLoginRequest>(async ({ input }) => {
...
})
}
}).createMachine({
initial: 'ProcessLogin',
states: {
ProcessLogin: {
invoke: {
src: 'processDeviceLogin',
input: ({ context }) => {
...
},
onDone: ({ event }) => {
...
},
onError: ({ event }) => {
...
}
}
}
}
}) I want to be able to extract the entire invocation into it's own method, i.e. const processLoginInvoke = {
src: 'processDeviceLogin',
input: ({ context }) => {
...
},
onDone: ({ event }) => {
...
},
onError: ({ event }) => {
...
}
} But I also want to maintain the typesafety of my actors, input, and event/context objects Is this possible? |
Beta Was this translation helpful? Give feedback.
Answered by
davidkpiano
Mar 28, 2025
Replies: 1 comment
-
There is currently no helper function for XState that does this, but it is possible in userland. The type you want is InvokeConfig<
TContext,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TEmitted,
TMeta
> Not all the type parameters are needed, depending on your use-case. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
CodenameLiam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is currently no helper function for XState that does this, but it is possible in userland.
The type you want is
InvokeConfig
:Not all the type parameters are needed, depending on your use-case.