Skip to content

Commit

Permalink
Create red-ants-lick.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 14, 2021
1 parent d0ebabf commit 1cd2681
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .changeset/red-ants-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
"xstate": minor
"@xstate/react": minor
---

Added the ability to tighten TS declarations of machine with generated metadata. This opens several exciting doors to being able to use typegen seamlessly with XState to provide an amazing typing experience.

The basics work like this:

```ts
const model = createModel({}, {
events: {
FOO: () => ({}),
BAR: () => ({}),
}
});

interface Meta {
__generated: 1;
eventsCausingServices: {
myService: 'FOO';
};
}

const machine = createMachine({
invoke: {
src: 'myService'
}
}, {
services: {
myService: async (context, event) => {
// event is typed to be { type: 'FOO' }
}
}
})
```

This works for guards, actions, delays - and also influences `state.matches` and `state.hasTag`.

0 comments on commit 1cd2681

Please sign in to comment.