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

Merge pull request #967 from andrewgordstewart/andrewgordstewart/add-tcontext-type-to-invoke-config #967

Conversation

andrewgordstewart
Copy link
Contributor

@andrewgordstewart andrewgordstewart commented Jan 29, 2020

With this change, the invoke.src property of a StateNodeConfig can perform type inference:

type UserContext = { foo: 'bar' };
type UserEvent = { type: 'READY' | 'SET' | 'GO' };
export const stateNode: StateNodeConfig<UserContext, any, UserEvent> = {
  invoke: {
    src: (ctx, event) => {
      switch (event.type) {
        case 'READY':
          // Property 'Foo' does not exist on type 'UserContext'. Did you mean 'foo'?ts(2551)
          return Promise.resolve(ctx.Foo);
        case 'SET':
          return Promise.resolve('SET');
        /// Type '"Go"' is not comparable to type '"READY" | "SET" | "GO"'.ts(2678)
        case 'Go':
          return Promise.resolve();
      }
    }
  }
};

See discussion starting here

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2020

🦋 Changeset is good to go

Latest commit: 520580b

We got this.

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 29, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 520580b:

Sandbox Source
youthful-snow-zwyvy Configuration
naughty-bhabha-z7oqp Configuration

@davidkpiano
Copy link
Member

Thanks @andrewgordstewart! Can you create a quick changeset? Just run yarn changeset in the root xstate directory (this will be a patch change).

@davidkpiano davidkpiano changed the title Pass TContext type to InvokeConfig Merge pull request #967 from andrewgordstewart/andrewgordstewart/add-tcontext-type-to-invoke-config Jan 29, 2020
@davidkpiano davidkpiano merged commit d221cd7 into statelyai:master Jan 29, 2020
@github-actions github-actions bot mentioned this pull request Jan 29, 2020
@andrewgordstewart andrewgordstewart deleted the andrewgordstewart/add-tcontext-type-to-invoke-config branch January 29, 2020 18:23
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.

None yet

2 participants