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

DX for typed events #65

Closed
cassiozen opened this issue Jul 28, 2021 · 7 comments · Fixed by #68
Closed

DX for typed events #65

cassiozen opened this issue Jul 28, 2021 · 7 comments · Fixed by #68

Comments

@cassiozen
Copy link
Owner

Hey @devanshj, when using types events, I'm getting a confusing error message. Here's a sample case:

1 - I have a types "UPDATE" event that requires a string value
2 - When trying send({ type: "UPDATE" }) it gives me an error (right, it is missing the value)
3 - Problem is, the error says Type '"UPDATE"' is not assignable to type '"some other type"':

Here is an example (the examples/form with this added send on line 57:
Screen Shot 2021-07-28 at 9 49 43 AM

@cassiozen
Copy link
Owner Author

I understand that TypeScript is showing one example of a correct possible value - but since you apparently can bend TypeScript to your will 🤪, can anything be done here?

@devanshj
Copy link
Contributor

devanshj commented Jul 28, 2021

you apparently can bend TypeScript to your will 🤪

HAHAHAHA this is 100% going to twitter xD

Could you send that code? I can't repro minimally. EDIT: oh wait you said it's from examples, looking into it

@devanshj
Copy link
Contributor

devanshj commented Jul 28, 2021

This is most probably a bug, so i'll report it to typescript team, meanwhile let me see if I can find a workaround

@devanshj
Copy link
Contributor

devanshj commented Jul 28, 2021

The repro is simpler than I thought xD I was guessing it takes time to compute hence typescript was showing bad errors

image

And the workaround is pretty simple - to add an overload, sending a PR

@cassiozen
Copy link
Owner Author

you apparently can bend TypeScript to your will

Stands true ;)

@cassiozen
Copy link
Owner Author

sending a PR

I'll publish the beta after we merge this then.

devanshj added a commit to devanshj/useStateMachine that referenced this issue Jul 28, 2021
as a workaround for typescript bug
cassiozen pushed a commit that referenced this issue Jul 28, 2021
as a workaround for typescript bug
@devanshj
Copy link
Contributor

devanshj commented Aug 5, 2021

For reference and reminder to revert overloads when #45217 gets fixed.

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

Successfully merging a pull request may close this issue.

2 participants