-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
XState version
XState version 5
Description
There's a TS error when using stateIn guard within a setup(...).createMachine(...) definition. With just createMachine(...) the error goes away.
➜ xstate-state-in-issue git:(main) ✗ npx tsc --noEmit
index.ts:26:9 - error TS2322: Type '{ guard: GuardPredicate<MachineContext, { type: "TOGGLE"; }, undefined, any>; }' is not assignable to type 'TransitionConfigOrTarget<MachineContext, { type: "TOGGLE"; }, { type: "TOGGLE"; }, never, never, never, never, EventObject, MetaObject>'.
Types of property 'guard' are incompatible.
Type 'GuardPredicate<MachineContext, { type: "TOGGLE"; }, undefined, any>' is not assignable to type 'GuardPredicate<MachineContext, { type: "TOGGLE"; }, undefined, never>'.
Type 'any' is not assignable to type 'never'.
26 TOGGLE: { guard: stateIn("idle") },
~~~~~~
Found 1 error in index.ts:26Here's the machine definition:
export const exampleMachineWithSetup = setup({
types: {
events: {} as { type: "TOGGLE" },
},
}).createMachine({
initial: "idle",
states: {
idle: {
on: {
TOGGLE: { guard: stateIn("idle") },
},
},
},
});Expected result
There should be no error, as with the standalone createMachine(...) definition.
Actual result
See the error message above.
Reproduction
https://github.com/aris-lvm/xstate-state-in-issue
Additional context
XState version: 5.20.2
TypeScript version: 5.9.2
Sorry for providing the repo instead of one of the templates. On CodeSandbox there was a completely unrelated TS error and StackBlitz confused me with it's AI.