-
Notifications
You must be signed in to change notification settings - Fork 36
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
Typegen doesn't support events name as enum #46
Comments
Typegen generator only takes into consideration the static shape of the config argument - basically, we require it to be JSON-like, fully serializable, and self-contained. We don't look up any external AST nodes - so this won't work for the time being (and I'm not sure if we'll be working on supporting this in the future). I'm also unsure if enums would work with the type machinery that consumes typegen metadata and that is implemented in XState itself. |
Fair enough, I always used enum based schemas to work around the lack of good TypeScript support. I guess that's not required anymore ❤️ I'm just wondering if some edge cases would require some kind of code duplication. E.g.: Properly type a prop/argument which would receive a state/event/service/action. It's quite straightforward with enums, but without them, that would require to create another type/enum, which would need maintenance over time, etc. Using the typegen file is not really an option, as it is meant to be a local devtool rather than a proper source code appendix, isn't it? I don't know if it's relevant, just wondering. But thanks for your feedback anyway 👌 |
Could you give me an example of what do you mean? |
Let's say, you have a component which interprets a machine, and would like to give its children its E.g.: const TheParent: React.FC = () => {
const [state] = useMachine(theMachine, {/* ... */});
return (
<TheChild state={state} />
)
};
const TheChild: React.FC<{ state: ? }> = ({ state }) => {
const showSomething = state.matches('something');
/* ... */
}; It's an obviously over simplified example, but you've got the point. And using React Context in conjunction with |
We export a bunch of helper types that can be used to help out with this - |
That's great, thanks. Didn't know their existence 👌 |
Maybe linked to the same root cause as #32?
I usually set my machines states/events/guards/actions name as enums, but migrating to Typegen, I noticed that the
schema.events
types doesn't support enums.Considering the following state machine:
The
event
argument of theonSubmit
action has thenever
type. But if I change theMachineEvents
for:It works as expected.
The text was updated successfully, but these errors were encountered: