Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Allow any action if action creators are not specified in model #2632

Merged
merged 2 commits into from Sep 14, 2021

Conversation

davidkpiano
Copy link
Member

@davidkpiano davidkpiano commented Sep 10, 2021

This PR fixes a regression noticed by some users - when they specified events but not actions in createModel(...), actions would be typed as never:

    const model = createModel(
      {},
      {
        events: {}
      }
    );

    model.createMachine({
      // TS will not compile
      entry: 'someAction',
      exit: { type: 'someObjectAction' },
    });

Fixes #2619

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2021

🦋 Changeset detected

Latest commit: f8cf5df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

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

@davidkpiano davidkpiano merged commit cda1b9e into main Sep 14, 2021
@davidkpiano davidkpiano deleted the davidkpiano/model-actions-fix branch September 14, 2021 12:44
@github-actions github-actions bot mentioned this pull request Sep 14, 2021
TComputedAction = 'actions' extends keyof TFinalModelCreators
? UnionFromCreatorsReturnTypes<TFinalModelCreators['actions']>
: never
TComputedAction = 'actions' extends keyof TModelCreators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has completely broken the inference of actions:

const model = createModel({ foo: 100 }, {
  events: {
    BAR: () => ({})
  }
})

model.createMachine({
  // ctx is being any
  entry: (ctx) => {},
  exit: assign({
    // ctx is being unknown
    foo: (ctx) => 42
  })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

createModel second param cause TS errors
3 participants