[4.10: TypeScript] Typed actions throw type errors
See original GitHub issueDescription
Hello everybody,
I just upgraded to version 4.10 ready to fix my send
types. I’m so happy about this release! Thank you so much for introducing the third generic toSendEvent
. I oftentimes had to go for <any, any>
as a workaround and am so glad to finally change those. 🖤
When defining an assign action within the configuration object, TypeScript goes nuts.
actions: {
assignCard: assign<MContext, SubmitEvent>({
card: (_, event) => event.data.name
})
}
I got the same error when passing the action to machine.withConfig()
.
Expected Result No type error should be thrown.
Actual Result TypeScript error pyramid of death 😬
Reproduction https://codesandbox.io/s/xstate-bug-typed-assign-action-in-configuration-object-5pc63?file=/src/index.tsx:1858-1981
Additional context
@xstate/react: 0.8.1,
xstate: 4.10.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:14 (12 by maintainers)
Top Results From Across the Web
[4.10: TypeScript] Typed actions throw type errors · Issue #1198
When defining an assign action within the configuration object, TypeScript goes nuts. ... I got the same error when passing the action to...
Read more >TypeScript error when using Remix action inferred types
My original code used actionData?.errors?.[input]?._errors[0] in the hasErrors() function, but it threw a cannot index errors with type string ...
Read more >Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >Type-Safe Error Handling In TypeScript - DEV Community
In this post, I introduce the concept of a Result type, which eliminates the need for throwing exceptions, and reduces risk of runtime ......
Read more >Changelog - Cypress Documentation
An error will no longer throw warning that cypress isn't a module after migrating a project's configuration file when using the direct download...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Or a different workaround, imo slightly nicer 😃
I assume this will get better in V5?
Workaround: