Bug: supplying generic input argument to setup actors for stubbing breaks invoke type inference
Author: sourcec0deCreated Apr 16, 2024Updated Feb 6, 2026
Labelsbug
XState version
XState version 5
Description
Hello :wave:
Running into a really odd typing problem when trying to create typed generic actor stubs and attempting to invoke them using src
The error I'm seeing is invoke
is not assignable to type 'undefined'This only seems to happen when providing generic input/output to a setup.actor.*
Here's a playground example.
import { fromPromise, setup } from 'xstate'
function createGenericMachine<
Input,
Output,
>() {
return setup({
types: {} as {
events: { type: 'trigger'; input: Input }
},
actors: {
resolver: fromPromise(
async (args: { input: Input }): Promise<Output> => {
throw new Error('not implemented')
},
),
},
}).createMachine({
initial: 'idle',
on: {
trigger: {
target: 'resolving',
},
},
states: {
idle: {},
resolving: {
// only happens when generic arguments are supplied to
// setup.actors.resolver
invoke: {
src: 'resolver',
input: ({ event }) => event.input,
onDone: { target: 'valid' },
onError: { target: 'invalid' },
},
},
valid: {},
invalid: {},
},
})
}
type input = {
in: string
}
type output = {
out: string
}
// type inference is working here
const machine = createGenericMachine<input, output>().provide({
actors: {
resolver: fromPromise(async({ input }) => {
console.log(input.in)
return {} as output
})
}
})Expected result
I should be able to supply generic arguments as input for a child actor without breaking xstate types.
Actual result
Supplying a generic argument as input breaks type inference on invoke.
Works fine outside this context and is correctly inferred from provide.
Removing the generic input parameter seems to resolve the type error.
But that leaves input untyped when using provide.
Reproduction
Additional context
No response
Source: statelyai/xstate