github statelyai/xstate xstate@4.29.0

latest releases: @xstate/store@1.0.0, xstate@5.13.2, xstate@5.13.1...
2 years ago

Minor Changes

  • #2674 1cd26811c Thanks @Andarist! - Using config.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! - Added t(), which can be used to provide types for schema 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 from github.com/davidkpiano to github.com/statelyai.

Don't miss a new xstate release

NewReleases is sending notifications on new releases.