xstate icon indicating copy to clipboard operation
xstate copied to clipboard

[core] "Extra" generic for actions, guards, etc.

Open davidkpiano opened this issue 3 years ago • 2 comments
trafficstars

This PR adds TExtra, first introduced in #2779. Separating this out so that we can implement model.withActions() and model.withGuards(), as well as future ideas for making machine implementations more type-safe.

    const model = createModel({ foo: 'string' }).withActions<
      { type: 'doThis'; greet: string } | { type: 'doThat' }
    >();

    model.createMachine(
      {},
      {
        actions: {
          doThis: () => {
            /* ... */
          },
          doThat: () => {
            /* ... */
          },
          // @ts-expect-error
          unspecified: () => {
            /* ... */
          }
        }
      }
    );

davidkpiano avatar Jan 01 '22 16:01 davidkpiano

⚠️ No Changeset found

Latest commit: b7c90df4a701dc8f93823ddd63dbbc4176b3e2b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jan 01 '22 16:01 changeset-bot[bot]

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

ghost avatar Jan 01 '22 16:01 ghost

This was somewhat superseded by all of the TAction, TGuard etc work. The model API is also not something that we have in v5.

Andarist avatar Sep 13 '23 11:09 Andarist