Closed VILLAN3LL3 closed 5 months ago
Three small issues:
state.matches(…)
in v5 does not accept a delimited.string.value
for compound state values; it must be represented as an object. // const matchesSubstate = current.matches('initial.substate.subsubstate1');
const matchesSubstate = current.matches({
initial: {
substate: 'substate1',
},
});
Here is a working example: https://stackblitz.com/edit/vitejs-vite-ngjvqn?file=src%2FApp.tsx
Thanks for your response. Yes I know that typegen is not yet ready for v5. That's why I use v4, see stackblitz example. @davidkpiano
Thanks for the clarification (the original issue stated XState v5).
The last 2 points still stand:
state.matches(…)
in v5 does not accept a delimited.string.value
for compound state values; it must be represented as an object.
XState version
XState version 4
Description
As my state machine definition is growing, I decided to move substates into separate objects in separate files.
It's now looking like this:
In separate files:
SUB_SUB_STATE_1
andSUB_SUB_STATE_2
are also of typeStateNodeConfig
. It's working fine, but the TypeScript typegen doesn't recognize the sub-states which results in errors referencing a substate in a react component. ThematchesStates
property of the typegen.ts File looks like this:matchesStates: "initial" | "initial.substate" | { "initial"?: "substate"; };
state.matches("initial.substate.subsubstate1.xyz")
will result in the error "No Overload Matches This Call".Expected result
the typegen.ts file should include all states which are configured within
createMachine
Actual result
The
matchesStates
property of the typegen.ts file is incomplete and looks like this:matchesStates: "initial" | "initial.substate" | { "initial"?: "substate"; };
state.matches("initial.substate.subsubstate1.xyz")
will result in the error "No Overload Matches This Call".Reproduction
https://stackblitz.com/edit/vitejs-vite-jmrvnd?file=src%2Fstate-machine.tsx
Additional context
No response