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

This commit is contained in:
Carlos Rodrigues 2019-10-15 17:26:20 +01:00 committed by Evan You
parent a3032b9b39
commit 0b2573f3d1

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