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: [Typescript] Failing to declare first parameter of guard breaks type inference in enqueueActions if another guard accepts dynamic parameters #5014

Open
taraldr opened this issue Aug 1, 2024 · 1 comment
Labels

Comments

@taraldr
Copy link

taraldr commented Aug 1, 2024

XState version

XState version 5

Description

Hi, love XState - just ported my teams typescript clients to XState, and came across this bug I think you might find interesting.

Parameter inference seems to break if you have:

  1. A guard which fails to declare the first parameter - () vs (_)
  2. Another guard which uses the second parameter - (_, params: { some: string )})
  3. An action using enqueueActions

This results in a typescript error on the action along the lines of, indicating that parameter type inference broke.

Type '{ type: "guardWithParams"; params: unknown; }' is not assignable to type '{ type: "guardWithParams"; params: { some: string; }; }'.

Workaround is always declaring the first parameter of all guards, even if unused.

@Andarist

Expected result

No type error.

Actual result

Type error.

Reproduction

https://stackblitz.com/edit/vitejs-vite-dwgz2w?file=src%2Fmain.ts&view=editor

Additional context

v5.16.0

@taraldr taraldr added the bug label Aug 1, 2024
@taraldr
Copy link
Author

taraldr commented Aug 1, 2024

Also observing the same behaviour if you have:

  1. An action which fails to declare the first parameter
  2. Another action which uses the second parameter
  3. A third action using enqueueActions

Repro: https://stackblitz.com/edit/vitejs-vite-kemb2g?file=src%2Fmain.ts&view=editor

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

1 participant