]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-dom): cast to the correct eventType instead of any (#292)
authorCarlos Rodrigues <david-181@hotmail.com>
Tue, 15 Oct 2019 16:26:20 +0000 (17:26 +0100)
committerEvan You <yyx990803@gmail.com>
Tue, 15 Oct 2019 16:26:19 +0000 (12:26 -0400)
packages/runtime-dom/src/directives/vOn.ts

index ccfda3758cc9c9801342e3dc2125c3c5867a6bf5..c1d788d52a783a08001361d47fd5e6d8b3a6a5fc 100644 (file)
@@ -1,5 +1,7 @@
 const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
 
+type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent;
+
 const modifierGuards: Record<
   string,
   (e: Event, modifiers?: string[]) => void | boolean
@@ -7,13 +9,13 @@ const modifierGuards: Record<
   stop: e => e.stopPropagation(),
   prevent: e => e.preventDefault(),
   self: e => e.target !== e.currentTarget,
-  ctrl: e => !(e as any).ctrlKey,
-  shift: e => !(e as any).shiftKey,
-  alt: e => !(e as any).altKey,
-  meta: e => !(e as any).metaKey,
-  left: e => 'button' in e && (e as any).button !== 0,
-  middle: e => 'button' in e && (e as any).button !== 1,
-  right: e => 'button' in e && (e as any).button !== 2,
+  ctrl: e => !(e as KeyedEvent).ctrlKey,
+  shift: e => !(e as KeyedEvent).shiftKey,
+  alt: e => !(e as KeyedEvent).altKey,
+  meta: e => !(e as KeyedEvent).metaKey,
+  left: e => 'button' in e && (e as MouseEvent).button !== 0,
+  middle: e => 'button' in e && (e as MouseEvent).button !== 1,
+  right: e => 'button' in e && (e as MouseEvent).button !== 2,
   exact: (e, modifiers) =>
     modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
 }