Contravariant Msg type in Dispatchable and LocalActorRef#148
Open
le0-0 wants to merge 5 commits intonactio:nextfrom
Open
Contravariant Msg type in Dispatchable and LocalActorRef#148le0-0 wants to merge 5 commits intonactio:nextfrom
le0-0 wants to merge 5 commits intonactio:nextfrom
Conversation
The tests are written like other jest tests but will fail on 'npm run typecheck' instead of 'npm run test'.
This caused StatelessActorProps to be considered <Unknown, ParentRef> instead of <Msg, ParentRef> in some cases.
f02e42d to
1f59a0b
Compare
…ed message types are partially unknown.
…k description`) Functions dispatch and query now accepts message types that are definitely supported, and only those, even if the actual type of messages that can be processed is partially unknown. Previous implementation did not accept ANY message type if processable messages was partially unknown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes LocalActorRef and Dispatchable contravariant.
Description
The type of the protocol field of Dispatchable was changed to a type that TypeScript recognizes as contravariant. This field doesn't seem to be used for anything else beside coaxing the type system. Please deny the PR if this assumption is wrong.
Fixing this surfaced an error related to the fact that StatelessActorProps was not exactly assignable to ActorProps, even though it probably should be. I fixed this as well.
Some changes to the types of dispatch and query functions were also necessary for them to work with new behavior of Dispatchable and LocalActorRef.
Related Issue
Fixes #147
Motivation and Context
The error, as outlined in the #147, causes the type system to disallow certain assigning statements that should be allowed and vice versa.
How Has This Been Tested?
npm run typecheck, notnpm run testnpm run typecheck, notnpm run testnpm run testin @nact/corenpm run typecheckin @nact/coreScreenshots (if appropriate):
The new test case I wrote went from this:

to this:

There's also more test cases in functions.test.ts that now pass.
Types of changes
I guess the interface for StatelessActorProps was changed slightly, so if this is actually used in explicit form anywhere. Like a field like this,let actorProps: StatelessActorProps<LocalActorSystemRef> = ..., that line will fail. I find that it was basically a bug that the line would be accepted anyway because there is no such signature for ActorProps (one without State and Msg). However, with the logic that existing code that would work now would end up not compiling, it could be classified as a breaking change.EDIT: Fixing of some edge case type logic has entailed changes to the types of dispatch and query as well as the original StatelessActorProps. It is hard to argue that this PR is anything other than a breaking change at this point.
Checklist: