]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(types): use explicit modifiers type (#10856)
authorbtea <2356281422@qq.com>
Mon, 6 May 2024 22:23:04 +0000 (06:23 +0800)
committerGitHub <noreply@github.com>
Mon, 6 May 2024 22:23:04 +0000 (06:23 +0800)
packages/dts-test/defineComponent.test-d.tsx
packages/runtime-dom/__tests__/directives/vOn.spec.ts
packages/runtime-dom/src/directives/vOn.ts

index 41646751b8b78999fdb78c8af23a86d7fe82cd1c..d2a39be2621370ea94263170c3273db96ec2a415 100644 (file)
@@ -1501,7 +1501,7 @@ describe('should work when props type is incompatible with setup returned type '
 
 describe('withKeys and withModifiers as pro', () => {
   const onKeydown = withKeys(e => {}, [''])
-  const onClick = withModifiers(e => {}, [''])
+  const onClick = withModifiers(e => {}, [])
   ;<input onKeydown={onKeydown} onClick={onClick} />
 })
 
index 03620f747e7abe897990510630db3294433087f4..ef7ee346ba814d963881e4090c39f9ca75fd258d 100644 (file)
@@ -43,7 +43,7 @@ describe('runtime-dom: v-on directive', () => {
   })
 
   test('it should support key modifiers and system modifiers', () => {
-    const keyNames = ['ctrl', 'shift', 'meta', 'alt']
+    const keyNames = ['ctrl', 'shift', 'meta', 'alt'] as const
 
     keyNames.forEach(keyName => {
       const el = document.createElement('div')
index 5a7d9e4af4a1b2dcad9edd47495599ec82107548..fd4010868cee942f62f911ea72d67ddd4aa1d391 100644 (file)
@@ -10,9 +10,21 @@ import { hyphenate, isArray } from '@vue/shared'
 const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']
 
 type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent
+type ModifierGuardsKeys =
+  | 'stop'
+  | 'prevent'
+  | 'self'
+  | 'ctrl'
+  | 'shift'
+  | 'alt'
+  | 'meta'
+  | 'left'
+  | 'middle'
+  | 'right'
+  | 'exact'
 
 const modifierGuards: Record<
-  string,
+  ModifierGuardsKeys,
   (e: Event, modifiers: string[]) => void | boolean
 > = {
   stop: e => e.stopPropagation(),
@@ -36,7 +48,7 @@ export const withModifiers = <
   T extends (event: Event, ...args: unknown[]) => any,
 >(
   fn: T & { _withMods?: { [key: string]: T } },
-  modifiers: string[],
+  modifiers: ModifierGuardsKeys[],
 ) => {
   const cache = fn._withMods || (fn._withMods = {})
   const cacheKey = modifiers.join('.')