types(runtime-dom): cast to the correct eventType instead of any (#292)
This commit is contained in:
		
							parent
							
								
									a3032b9b39
								
							
						
					
					
						commit
						0b2573f3d1
					
				@ -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`])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user