-
-
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: Type issue with not
helper
#5090
Comments
I also found this issue which seems to have the same issue, but was closed without further investigation. And as the reproduction above seems to prove, this doesn't seem to have anything to do with the size of the machines. |
I think I just encountered this issue when trying the machine from here: https://github.com/Devessier/xstatebyexample/blob/main/src/examples/video-player/machine.ts with
I found adding;
resolved the squiggly line, which I considered after this explanation: microsoft/TypeScript#58176 (comment) |
A way to eliminate this error seems to be--if using e.g.: const machine = setup({
guards: {
foo: () => true,
bar: () => false,
}
}).createMachine({
always: {
guard: and(['foo', 'bar']), // <-- BAD
actions: log('success')
}
}); Instead: const machine = setup({
guards: {
foo: () => true,
bar: () => false,
fooAndBar: and(['foo', 'bar']),
}
}).createMachine({
always: {
guard: 'fooAndBar', // <-- OK
actions: log('success')
}
}); |
@Andarist, @davidkpiano: I don't know how "popular" this problem is, but I think the above gives a clue to where it lies. The first example results in a type explosion, but the second does not. Probably worth looking at using the "native" Still, the compiler won't protest without a sufficiently complex machine. Since I have (several!) handy which exhibit this behavior, I'll take a closer look whenever the planets align. |
XState version
XState version 5
Description
I'm trying to create a package that creates a reusable state machine. I've simplified our machine to locate the error being the
not
function:Expected result
I expected the typings to be built without issues.
Actual result
When trying to build types for the packages, I get the following error:
It seems like the issue stems from the
not
function referencing theGuardPredicate
type which is not exported by XState and TypeScript is unable to build a type for it without this reference.Reproduction
https://codesandbox.io/p/devbox/angry-goldberg-v42j8m?workspaceId=4a3e8946-02ff-4af1-aeb6-deeb01d9e58a
Additional context
Try running
pnpm run build
in the reproduction and you will see the error. For some reason, the error doesn't occur when using......in tsconfig.json. But that doesn't seem like a viable solution as that causes other module issues and is not really recommended by TS at this point.
The text was updated successfully, but these errors were encountered: