Minor Changes
-
#2674
1cd26811c
Thanks @Andarist! - Usingconfig.schema
becomes the preferred way of "declaring" TypeScript generics with this release:createMachine({ schema: { context: {} as { count: number }, events: {} as { type: 'INC' } | { type: 'DEC' } } })
This allows us to leverage the inference algorithm better and unlocks some exciting possibilities for using XState in a more type-strict manner.
-
#2674
1cd26811c
Thanks @Andarist, @mattpocock! - 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.With the VS Code extension, you can specify a new attribute called
tsTypes: {}
in your machine definition:const machine = createMachine({ tsTypes: {} });
The extension will automatically add a type assertion to this property, which allows for type-safe access to a lot of XState's API's.
⚠️ This feature is in beta. Actions/services/guards/delays might currently get incorrectly annotated if they are called "in response" to always transitions or raised events. We are working on fixing this, both in XState and in the typegen.
Patch Changes
-
#2962
32520650b
Thanks @mattpocock! - Addedt()
, which can be used to provide types forschema
attributes in machine configs:import { t, createMachine } from 'xstate'; const machine = createMachine({ schema: { context: t<{ value: number }>(), events: t<{ type: 'EVENT_1' } | { type: 'EVENT_2' }>() } });
-
#2957
8550ddda7
Thanks @davidkpiano! - The repository links have been updated fromgithub.com/davidkpiano
togithub.com/statelyai
.