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: typegen types resolving events to never in guards/actions #3102

Closed
SimeonC opened this issue Mar 2, 2022 · 1 comment · Fixed by #3230
Closed

Bug: typegen types resolving events to never in guards/actions #3102

SimeonC opened this issue Mar 2, 2022 · 1 comment · Fixed by #3230

Comments

@SimeonC
Copy link
Contributor

SimeonC commented Mar 2, 2022

Description

I only have this occurring in my one machine and it's fairly difficult to reduce down to a easy reproduction as I couldn't figure out what was the same between the errors. I attached a Typescript playground illustrating the issue with the working actions/implementations commented out. (The typegen is amazing BTW, so much easier and I can remove a lot of checks, looking forward to a CLI tool ✨ )

Expected result

Event type should be correctly inferred for all actions/guards

Actual result

event is resolved to never in certain guards and actions.

Reproduction

Typescript Playground Link

Additional context

xstate 4.30.3

@Andarist
Copy link
Member

Andarist commented Mar 2, 2022

Huh, this is quite interesting! So it seems that the issue is within our IndexByType helper that is used behind the scenes, see this TS playground. The issue here is that it doesn't process event types that are unions correctly.

A different version of this type works OK, see here. Key remapping for mapped types was introduced in TS 4.1 though so I need to rethink compatibility implications here or figure out a different filtering strategy than using Extract. For instance, an intersection works quite OK, see here.

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