Skip to content
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 error when referencing guard with check inside setup #4834

Open
with-heart opened this issue Apr 7, 2024 · 1 comment
Open

Bug: type error when referencing guard with check inside setup #4834

with-heart opened this issue Apr 7, 2024 · 1 comment
Assignees
Labels

Comments

@with-heart
Copy link
Contributor

XState version

XState version 5

Description

The check function provided by enqueueActions can't be used to reference a guard by type or by parameterized object.

Expected result

I expected check to not cause a type error when referencing a guard.

Actual result

check causes a type error when referencing a guard.

Reproduction

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240331#code/JYWwDg9gTgLgBAbzgZwKYwK5gDR1QOwEcNUSBBAYxmAn2TgF84AzKCEOAIgA9kYBDGKk4BuOAHpxcGAE8wqZAC44AVgB0ATjUBGAFC60mMAAoEuuNLkLlZixYq0h3GDab96SGAAtg+AObK-PgyjNjmdqgAbgQwSohuHpbyypxYACaCwmLevgFwQSEMYRZF4fxUNHQ24RbpmQAqPv7KBMSkqJTUtMjGpnAUXqgUANaMAJRwALwAfIg1dsDMcMYDQ8PGnF7ujbkAwlv+qGmcYxO2diXzFovLqyN9sslcW8g7-vtBfkec42dXjPMGGNiqFwn4MPwoGk4ucLC83n4Poc0so+g58E4YLgojFxlNZrC7FB0BgoPh+o5UM41Dl-HAAISTSZ4aIYmlNPwiQEg0pArlAA

Additional context

Maybe related to the cause of #4820 but opening for tracking

@Andarist
Copy link
Member

Andarist commented Apr 9, 2024

It's both the same as the other issue and different. Some of the underlying mechanisms are the same but it feels like this one should be easier for TS to infer - something is obviously missing in the implementation there.

Things break as soon as we include context-sensitive functions in guards. You can see how it works OK without them: TS playground

I highly doubt it's fixable on our side right now (I intend to work on this in the compiler but it won't happen too soon). Our current best bet to work around this would be to introduce this API: #4703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants