From 51f3179bcc44067b6ebc5f9c63cb92a0a751b2fe Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 19 May 2022 09:31:21 -0400 Subject: [PATCH] chore(): add stronger typing to the tapclick utility (#25316) --- core/src/utils/tap-click.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/utils/tap-click.ts b/core/src/utils/tap-click.ts index b0c0577d37..19a0ce0829 100644 --- a/core/src/utils/tap-click.ts +++ b/core/src/utils/tap-click.ts @@ -57,7 +57,7 @@ export const startTapClick = (config: Config) => { } }; - const pointerDown = (ev: any) => { + const pointerDown = (ev: UIEvent) => { if (activatableEle || isScrolling()) { return; } @@ -165,9 +165,17 @@ export const startTapClick = (config: Config) => { doc.addEventListener('contextmenu', onContextMenu, true); }; -const getActivatableTarget = (ev: any): any => { +const getActivatableTarget = (ev: UIEvent): any => { if (ev.composedPath) { - const path = ev.composedPath() as HTMLElement[]; + /** + * composedPath returns EventTarget[]. However, + * objects other than Element can be targets too. + * For example, AudioContext can be a target. In this + * case, we know that the event is a UIEvent so we + * can assume that the path will contain either Element + * or ShadowRoot. + */ + const path = ev.composedPath() as Element[] | ShadowRoot[]; for (let i = 0; i < path.length - 2; i++) { const el = path[i]; if (!(el instanceof ShadowRoot) && el.classList.contains('ion-activatable')) { @@ -175,7 +183,7 @@ const getActivatableTarget = (ev: any): any => { } } } else { - return ev.target.closest('.ion-activatable'); + return (ev.target as Element).closest('.ion-activatable'); } };