-
Notifications
You must be signed in to change notification settings - Fork 38
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
fix(network, DHT): stricter typing for event listeners in interfaces #2517
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do the
on
,off
andonce
types need to be defined multiple times per function type.
This is no longer an issue, could remove it from the "Future improvements" list
packages/utils/src/EmitterOf.ts
Outdated
type OverloadedListenerSetter<T> = Intersection<ListenerSetterTypes<T>> | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type EmitterOf<T> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This give bit strange error messages:
e.g.
const emitter: Layer1Node = {} as any
emitter.on('manualRejoinRequired', (foo: any) => {})
No overload matches this call.
The last overload gave the following error.
Argument of type '"manualRejoinRequired"' is not assignable to parameter of type '"ringContactRemoved"'.ts(2769)
Maybe good to add a bullet point about that into the "Future improvements" section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird but I believe this is just overloading errors are reported in this case, as the assigned listener has any type in the first parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be merged to main.
Eslint broken here for some reason |
Summary
Stricter listener typing for events in the
ITransport
andLayer1Node
interfaces.It is no longer possible to set a listener with an inproper listener function for example:
layer1Node.on('manualRejoinRequired', (peerDescriptor: PeerDescriptor) => {})
will now be caught by the compiler.
Changes