From 5d3246c37719076bc745d37bf610236ed0434815 Mon Sep 17 00:00:00 2001 From: Sebastian Ware Date: Mon, 4 Dec 2023 11:47:56 +0100 Subject: [PATCH 1/3] Add specificity to fix a type error with addEventListener --- packages/inferno/src/DOM/utils/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inferno/src/DOM/utils/common.ts b/packages/inferno/src/DOM/utils/common.ts index 62f6b207c..9d926e3ae 100644 --- a/packages/inferno/src/DOM/utils/common.ts +++ b/packages/inferno/src/DOM/utils/common.ts @@ -33,7 +33,7 @@ if (process.env.NODE_ENV !== 'production') { Object.freeze(EMPTY_OBJ); } -export function normalizeEventName(name): string { +export function normalizeEventName(name): keyof DocumentEventMap { return name.substring(2).toLowerCase(); } From 2432acae3eb4c956b16c2303d3f470ecc27a5da8 Mon Sep 17 00:00:00 2001 From: Sebastian Ware Date: Mon, 4 Dec 2023 11:48:28 +0100 Subject: [PATCH 2/3] addEventListener won't accept SemiSyntheticEvent due to extra helper methods, so we need to mark them as optional. --- packages/inferno/src/DOM/events/delegation.ts | 4 +--- packages/inferno/src/core/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/inferno/src/DOM/events/delegation.ts b/packages/inferno/src/DOM/events/delegation.ts index a2db5387b..4ceb5162b 100644 --- a/packages/inferno/src/DOM/events/delegation.ts +++ b/packages/inferno/src/DOM/events/delegation.ts @@ -184,9 +184,7 @@ function rootEvent(name: string): (event: SemiSyntheticEvent) => void { function attachEventToDocument( name: string, ): (event: SemiSyntheticEvent) => void { - const attachedEvent = rootEvent(name); - // @ts-expect-error TODO: FIXME + const attachedEvent = rootEvent(name); document.addEventListener(normalizeEventName(name), attachedEvent); - return attachedEvent; } diff --git a/packages/inferno/src/core/types.ts b/packages/inferno/src/core/types.ts index c273acc74..9a098868d 100644 --- a/packages/inferno/src/core/types.ts +++ b/packages/inferno/src/core/types.ts @@ -79,8 +79,8 @@ export interface SemiSyntheticEvent extends Event { * A reference to the element on which the event listener is registered. */ currentTarget: EventTarget & T; - isDefaultPrevented: () => boolean; - isPropagationStopped: () => boolean; + isDefaultPrevented?: () => boolean; + isPropagationStopped?: () => boolean; } export type ClipboardEvent = SemiSyntheticEvent & NativeClipboardEvent; From c385595b70aa2ed9bee74eac5949396e7f836dfb Mon Sep 17 00:00:00 2001 From: Sebastian Ware Date: Thu, 18 Jan 2024 22:02:36 +0100 Subject: [PATCH 3/3] Fix linting error --- packages/inferno/src/DOM/events/delegation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inferno/src/DOM/events/delegation.ts b/packages/inferno/src/DOM/events/delegation.ts index 4ceb5162b..b0708ae4c 100644 --- a/packages/inferno/src/DOM/events/delegation.ts +++ b/packages/inferno/src/DOM/events/delegation.ts @@ -184,7 +184,7 @@ function rootEvent(name: string): (event: SemiSyntheticEvent) => void { function attachEventToDocument( name: string, ): (event: SemiSyntheticEvent) => void { - const attachedEvent = rootEvent(name); + const attachedEvent = rootEvent(name); document.addEventListener(normalizeEventName(name), attachedEvent); return attachedEvent; }