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.
We add types to a
EventEmitter
class which extends the plain jsEventTarget
.The name is chosen to give familiarity to node developers but it's not generally a good idea.
This refactor:
TypedEventTarget
interface which adds types toEventTarget
EventEmitter
toTypedEventEmitter
to draw a distinction between themTypedEventEmitter
asEventEmitter
to preserve backwards compatibilityIn the future all consuming code should rely on the
TypedEventTarget
interface while implementing code usesTypedEventEmitter
as an implementation of aTypedEventEmitter
.By depending on the interface and not the implementation consuming code is isolated from problems that arise when two versions of
@libp2p/interface
is in the dependency tree and the event subsystems would otherwise be compatible due to type overlap.This manifests as an error message about incompatible implementations of the private
#listeners
field in EventEmitter.Backwards compatibility is achieved by exporting the
TypedEventEmitter
class as the olderEventEmitter
name. This should be removed in a future PR to the v1.0 branch once external modules (e.g. Gossipsub) have been updated to use the newTypedEventEmitter
symbol.Change checklist