Skip to content

Commit

Permalink
Fix attachEvent type error (#1661)
Browse files Browse the repository at this point in the history
* Add specificity to fix a type error with addEventListener

* addEventListener won't accept SemiSyntheticEvent due to extra helper methods, so we need to mark them as optional.

* Fix linting error
  • Loading branch information
jhsware committed Jan 20, 2024
1 parent ca227a5 commit 35ce542
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 0 additions & 2 deletions packages/inferno/src/DOM/events/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ function attachEventToDocument(
name: string,
): (event: SemiSyntheticEvent<any>) => void {
const attachedEvent = rootEvent(name);
// @ts-expect-error TODO: FIXME
document.addEventListener(normalizeEventName(name), attachedEvent);

return attachedEvent;
}
2 changes: 1 addition & 1 deletion packages/inferno/src/DOM/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/inferno/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export interface SemiSyntheticEvent<T> 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<T> = SemiSyntheticEvent<T> & NativeClipboardEvent;
Expand Down

0 comments on commit 35ce542

Please sign in to comment.