Skip to content

Commit 0edbfe7

Browse files
authored
fix: remove CustomEvent polyfill (#2652)
The EventTarget implementation of libp2p contained workarounds for incomplete runtime support for the feature. One of the workarounds was specifically marked to be removed once CustomEvent was implemented in NodeJS and the [upstream ticket](nodejs/node#40678) was closed. This has happened two years ago. The implementation of the standard event in Node18 and the subsequent removal of the experimental flag in Node19 broke the current workaround and causes tsc to error. Some of these were suppressed with @ts-ignore, others were not. This fix closes #2420. The fix removes the workaround as instructed by the source code and restores compatibility with recent versions of Node types.
1 parent fd4aea3 commit 0edbfe7

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

packages/interface/src/event-target.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,4 @@ export class TypedEventEmitter<EventMap extends Record<string, any>> extends Eve
105105
}
106106
}
107107

108-
/**
109-
* CustomEvent is a standard event but it's not supported by node.
110-
*
111-
* Remove this when https://github.com/nodejs/node/issues/40678 is closed.
112-
*
113-
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
114-
*/
115-
class CustomEventPolyfill<T = any> extends Event {
116-
/** Returns any custom data event was created with. Typically used for synthetic events. */
117-
public detail: T
118-
119-
constructor (message: string, data?: EventInit & { detail: T }) {
120-
super(message, data)
121-
// @ts-expect-error could be undefined
122-
this.detail = data?.detail
123-
}
124-
}
125-
126-
export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill
108+
export const CustomEvent = globalThis.CustomEvent

0 commit comments

Comments
 (0)