-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0ebabf
commit 1cd2681
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |