From 0edbfe7af1ccf4bd23dd78b2bcc29ecf54ea02eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=96nal?= Date: Fri, 9 Aug 2024 07:32:49 -0700 Subject: [PATCH] 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](https://github.com/nodejs/node/issues/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. --- packages/interface/src/event-target.ts | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/interface/src/event-target.ts b/packages/interface/src/event-target.ts index f09d127ef4..de967c61ff 100644 --- a/packages/interface/src/event-target.ts +++ b/packages/interface/src/event-target.ts @@ -105,22 +105,4 @@ export class TypedEventEmitter> extends Eve } } -/** - * CustomEvent is a standard event but it's not supported by node. - * - * Remove this when https://github.com/nodejs/node/issues/40678 is closed. - * - * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent - */ -class CustomEventPolyfill extends Event { - /** Returns any custom data event was created with. Typically used for synthetic events. */ - public detail: T - - constructor (message: string, data?: EventInit & { detail: T }) { - super(message, data) - // @ts-expect-error could be undefined - this.detail = data?.detail - } -} - -export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill +export const CustomEvent = globalThis.CustomEvent