Browse Source

types(runtime-dom): cast to the correct eventType instead of any (#292)

Carlos Rodrigues 6 years ago
parent
commit
0b2573f3d1
1 changed files with 9 additions and 7 deletions
  1. 9 7
      packages/runtime-dom/src/directives/vOn.ts

+ 9 - 7
packages/runtime-dom/src/directives/vOn.ts

@@ -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`])
 }