Open rostero1 opened 5 months ago
This has nothing to do with assign
. With setup
API our whole config is the target of inference - inferred type arguments are exempt from excess property check (which is something between a lint rule and a hard error in TS). We can't do anything about it right now - this is how TS works.
I'm such a beginner at typescript, even more so relatively. Why does it catch the following when I remove the actions:
import { setup, assign } from 'xstate';
type Events = { type: 'RUN' };
type Context = {};
setup({
types: {
events: {} as Events,
context: {} as Context,
},
actions: {
doAction: assign(({ context }) => {
return context;
}),
},
}).createMachine({
initial: 'idle',
states: {
idle: {
on: {
RUN: { thing: 'stop' },
},
},
stop: {},
},
});
With Type '{ thing: string; }' is not assignable to type 'TransitionConfigOrTarget<Context, Events, Events, never, { type: "doAction"; params: NonReducibleUnknown; }, never, never, EventObject>'.
XState version
XState version 5
Description
In the code below,
thing
is allowed in theRUN
transition. If you remove theactions: 'doAction'
then it will properly catch the error and not allowthing
. This seems to be specific toassign
.In my real world code, I accidentally had
type:
instead oftarget:
and it took a bit to figure out why my machine wasn't working as expected.Expected result
thing
is not assignable to type 'TransitionConfigOrTarget`Actual result
It type checks
Reproduction
https://stackblitz.com/edit/vitejs-vite-9vip7x?file=src%2Fmachine.ts,tsconfig.json&terminal=dev
Additional context
No response