Optional inputs in v5 #4819
Unanswered
AnatoleLucet
asked this question in
Q&A
Replies: 1 comment 1 reply
-
This one works with // @exactOptionalPropertyTypes: true
import { setup, createActor } from "xstate"; // types: 5.9.1
const test = setup({
types: {} as {
input:
| {
foo?: string;
}
| undefined;
},
}).createMachine({
context: ({ input = {} }) => ({
foo: input.foo ?? "bar",
}),
});
createActor(test);
createActor(test, { input: undefined });
createActor(test, { input: { foo: "" } }); Inference from optional properties is a little bit weird in this sense. I'll have to think more about potential solutions for this on our side. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to create a state machines which takes optional inputs, but I cannot figure out how to do this using the
input()
function.Beta Was this translation helpful? Give feedback.
All reactions