Skip to content

Commit 0b2573f

Browse files
pikaxyyx990803
authored andcommitted
types(runtime-dom): cast to the correct eventType instead of any (vuejs#292)
1 parent a3032b9 commit 0b2573f

File tree

1 file changed

+9
-7
lines changed
  • packages/runtime-dom/src/directives

1 file changed

+9
-7
lines changed

packages/runtime-dom/src/directives/vOn.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
22

3+
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent;
4+
35
const modifierGuards: Record<
46
string,
57
(e: Event, modifiers?: string[]) => void | boolean
68
> = {
79
stop: e => e.stopPropagation(),
810
prevent: e => e.preventDefault(),
911
self: e => e.target !== e.currentTarget,
10-
ctrl: e => !(e as any).ctrlKey,
11-
shift: e => !(e as any).shiftKey,
12-
alt: e => !(e as any).altKey,
13-
meta: e => !(e as any).metaKey,
14-
left: e => 'button' in e && (e as any).button !== 0,
15-
middle: e => 'button' in e && (e as any).button !== 1,
16-
right: e => 'button' in e && (e as any).button !== 2,
12+
ctrl: e => !(e as KeyedEvent).ctrlKey,
13+
shift: e => !(e as KeyedEvent).shiftKey,
14+
alt: e => !(e as KeyedEvent).altKey,
15+
meta: e => !(e as KeyedEvent).metaKey,
16+
left: e => 'button' in e && (e as MouseEvent).button !== 0,
17+
middle: e => 'button' in e && (e as MouseEvent).button !== 1,
18+
right: e => 'button' in e && (e as MouseEvent).button !== 2,
1719
exact: (e, modifiers) =>
1820
modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
1921
}

0 commit comments

Comments
 (0)