feat: add generic parameter for IEventPublisher in EventBus#1930
Open
lucas-gregoire wants to merge 2 commits intonestjs:masterfrom
Open
feat: add generic parameter for IEventPublisher in EventBus#1930lucas-gregoire wants to merge 2 commits intonestjs:masterfrom
lucas-gregoire wants to merge 2 commits intonestjs:masterfrom
Conversation
04605e0 to
c41d5b4
Compare
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, the
EventBus.publishandEventBus.publishAllmethods always returnany, whereas they could infer types from thepublishandpublishAllmethods of theIEventPublisherinterface.What is the new behavior?
This PR introduces a new generic parameter for the
EventBuswhich represents the type of the event publisher (extendingIEventPublisher), allowing to infer the return types of thepublishandpublishAllmethods.If the event publisher does not have a
publishAllmethod—like in the case ofDefaultPubSub—then the return type ofpublishAllis an array of thepublishresults from the publisher. This clarifies the behavior of thepublishAllmethod.By default,
publishstill returnsanywhilepublishAllnow returnsany[]which better matches the returned array.Does this PR introduce a breaking change?
publishAllnow returnsany[]instead ofanyby default. I think this is a "soft" breaking change.For this breaking change, here are the situations to consider:
publishAllwithout using its result: no change.publishAll:publishAllmethod:publishAllmethod:publishAll: this cast will still compile but could be replaced by the inference allowed by the new generic parameter.Personally, I think this is a breaking change with not much impact.
Other information
I took the opportunity of this PR to add the
expect-typelibrary to more easily test types and generics. I selected this lib among many others (tsd,ts-expect,type-testing,tstyche) because this one is still maintained, used by many projects, and relatively comprehensive. If you have other suggestions, feel free to share them.I also added some missing generics tests on query handlers.