You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
· 3 comments
Thank you so much for posting this @taraldr I thought I was going crazy.
Been poring over my code for the past few hours trying to figure out why on earth it was complaining about this. In my case I had an action using typed params, which would work alone. But as soon as I added in anything else (guards/actions/etc) it would error on all of them. Incredibly frustrating to try and debug as a brand new XState user.
I thought it had to do with my enqueue actions usage or needing to better type my actions, had no idea this was the cause till I decided to work backward from the broken guards instead and saw this issue.
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:
()
vs(_)
(_, params: { some: string )})
This results in a typescript error on the action along the lines of, indicating that parameter type inference broke.
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-iqaqw4d9?file=src%2Fmain.ts
Additional context
v5.16.0
The text was updated successfully, but these errors were encountered: