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

Fixed an issue with ActorRefFrom not resolving the typegen metadata from machine types #3087

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

Andarist
Copy link
Member

Fixed the second issue reported here: #3028

@Andarist Andarist requested a review from davidkpiano February 24, 2022 10:46
@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2022

🦋 Changeset detected

Latest commit: 1d4de2c

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

@ghost
Copy link

ghost commented Feb 24, 2022

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

@codesandbox-ci
Copy link

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 1d4de2c:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

infer TTypestate,
any,
any,
any
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue was that we were not using infer TResolvedTypesMeta here and I could have fixed it with a two-line change (infer here + provide the result to StateMachine below). However, I've chosen to refactor this type to use ReturnTypeOrValue<T> extends infer R technique so we don't end up in such problems - as it ensures that we infer from direct types and factories in the very same way.

const createChild = () => createMachine({});

function createParent(_deps: {
spawnChild: () => ActorRefFrom<typeof createChild>;
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue was that in here we are unpacking the type from a factory but spawn below actually unpacks from a machine (since the result of a factory is passed to it). Since resolving from factories and types was not unified... it caused a type mismatch.

Comment on lines +494 to +496
createParent({
spawnChild: () => spawn(createChild())
});
Copy link
Member Author

Choose a reason for hiding this comment

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

I wish I could write a better test case for this, but unfortunately, within createMachine call TS gets lost when computing variance types and it allows what shouldn't be allowed. Since this is a known problem and there is a fix for it I've rechecked with an insiders build but it didn't end up erroring there either. I've reported this as a potential issue here: microsoft/TypeScript#45628 (comment)

@Andarist Andarist merged commit ae95794 into main Feb 24, 2022
@Andarist Andarist deleted the fix/3028-2 branch February 24, 2022 15:39
This was referenced Feb 24, 2022
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.

2 participants