-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: AssignAction
type error when using exactOptionalPropertyTypes: true
#4613
Comments
@Andarist is there any workaround for this? Do you know if it's possible to disable |
I updated XState and TypeScript in this codebase and it seems to work fine: https://stackblitz.com/edit/vitejs-vite-lbw4wa?file=package.json,src%2Fmain.ts Can you double-check that everything's working on your end? |
@davidkpiano it seems to be working now when only When instead I add also |
I wasn't yet able to figure out a workaround. It's definitely possible to fix this on our side but it requires prioritization and time.
No, it's a global setting. |
Facing similar issue. Will really appreciate if any workaround is available. Thanks for your time and effort |
Can you share the code that's causing the issue for you? |
sure.. import { assign, createActor, fromPromise, setup } from "xstate";
const machine = setup({
types: { context: {} as { value: number } },
actors: {
child: fromPromise(() => Promise.resolve(10))
}
}).createMachine({
id: "test",
initial: "inactive",
context: () => ({ value: 1 }),
invoke: {
src: "child",
onDone: {
actions: assign(({ event }) => ({ value: event.output }))
}
},
states: {
active: { on: { toggle: "inactive" } },
inactive: { on: { toggle: "active" } }
}
});
const actor = createActor(machine);
actor.subscribe(console.log);
actor.start(); Getting following error
|
I'm also seeing this sort of error when
Example: import { timer } from 'rxjs';
import { setup, fromObservable, createActor, assign } from 'xstate';
const machine = setup({
types: { context: {} as { value: number }, events: {} as { type: 'start' } },
actors: {
child: fromObservable(() => timer(5_000)),
},
}).createMachine({
id: 'test',
initial: 'notStarted',
context: { value: 1 },
states: {
notStarted: {
on: {
// Type 'ProvidedActor' is not assignable to type '{ src: "child";...
start: {
target: 'running',
actions: assign({
value: ({ context }) => context.value + 1,
}),
},
},
},
running: {
invoke: {
src: 'child',
onDone: {
target: 'done',
},
},
},
done: { type: 'final' },
},
});
const actor = createActor(machine);
actor.subscribe((snapshot) => console.log(snapshot.value, snapshot));
actor.start();
document.addEventListener('click', () => actor.send({ type: 'start' })); Produces the following error on the indicated line in the example (
|
I'm also seeing this type error with
As @SandroMaglione noted, the issue only manifests when at least one Here's a variation of @bhvngt's example to illustrate: import { assign, createActor, fromPromise, setup } from 'xstate';
const machine = setup({
types: { context: {} as { value: number } },
/////////// Comment this chunk out and the type error on "toggle" disappears
actors: {
child: fromPromise(() => Promise.resolve(10)),
},
///////////////// end chunk
}).createMachine({
id: 'test',
initial: 'inactive',
context: () => ({ value: 1 }),
states: {
active: {
on: {
// Type error on `toggle` here
toggle: { target: 'inactive', actions: assign({ value: () => 0 }) },
},
},
inactive: { on: { toggle: 'active' } },
},
});
const actor = createActor(machine); Link to stackblitz: https://stackblitz.com/edit/node-lsnym4?file=index.ts |
Also seeing this. Seems like only option is to disabled |
XState version
XState version 5
Description
An
assign
action reports a type error when usingexactOptionalPropertyTypes: true
intsconfig.json
.Expected result
It should be possible to use
exactOptionalPropertyTypes: true
withxstate
.Actual result
Reproduction
https://stackblitz.com/edit/vitejs-vite-lbw4wa?file=src%2Fmain.ts
Additional context
exactOptionalPropertyTypes
allows for more type-safety. It is also recommended when using@effect/schema
.The text was updated successfully, but these errors were encountered: