Make EventBus types a little bit more strict #17399
Unanswered
ghost23
asked this question in
Ideas / Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
consider this little code example:
This currently does not lead to an error, but I think it would be nice, if it did.
Because currently I have no way of enforcing an eventBus to support a specific set of typed events, because you can always simply assign any EventBus instance to any eventBus variable.
And by the way, this also does not lead to an error:
I believe the way this could be fixed would be to simply change the Typescript definition for the EventBus class as follows:
Notice the "in out" that has been added, which sets the variance of the generic class specifically to invariant. This needs Typescript 4.7 or higher.
Beta Was this translation helpful? Give feedback.
All reactions