-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
… from machine types
🦋 Changeset detectedLatest commit: 1d4de2c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
CodeSee Review Map:Review in an interactive map View more CodeSee Maps Legend |
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:
|
infer TTypestate, | ||
any, | ||
any, | ||
any |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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.
createParent({ | ||
spawnChild: () => spawn(createChild()) | ||
}); |
There was a problem hiding this comment.
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)
Fixed the second issue reported here: #3028