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 in the EmittedFrom type helper that could prevent it from inferring the desired type from some service #3292

Merged
merged 2 commits into from
May 13, 2022

Conversation

Andarist
Copy link
Member

… from inferring the desired type from some service
@Andarist Andarist requested a review from davidkpiano May 13, 2022 11:52
@changeset-bot
Copy link

changeset-bot bot commented May 13, 2022

🦋 Changeset detected

Latest commit: 8b96e09

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 May 13, 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

codesandbox-ci bot commented May 13, 2022

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 8b96e09:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

@@ -1799,7 +1799,7 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
}

export type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R
? R extends ActorRef<infer _, infer TEmitted>
? R extends ActorRef<any, infer TEmitted>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is somewhat weird because my intuition was that it should not work when R has TEvent configured as never.

And indeed it shouldn't work as per this playground. So it got me thinking... and I've realized that those becomes assignable when we turn off the strictFunctionTypes (see here).

The weird thing is that... our tests should be type-checked using strict mode but apparently this doesn't quite work 🤷‍♂️

Gonna fix this up in a sec.

@@ -1799,7 +1799,9 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
}

export type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R
? R extends ActorRef<infer _, infer TEmitted>
? R extends Interpreter<infer _, infer __, infer ___, infer ____, infer _____>
Copy link
Member Author

Choose a reason for hiding this comment

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

this might look a little bit strange because Interpreter implements ActorRef and ActorRef is already handled here - but, unfortunately, while it implements the ActorRef, its send method's signature is different and TS might not be able to actually treat it as ActorRef for the purpose of conditional types with infer

@Andarist Andarist merged commit 16514e4 into main May 13, 2022
@Andarist Andarist deleted the fix/emitted-from-with-services branch May 13, 2022 12:37
@github-actions github-actions bot mentioned this pull request May 13, 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.

None yet

2 participants