From 204f9a2e410824676b4b16b3e338b1cfc6845091 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 3 May 2024 10:42:19 +0800 Subject: [PATCH 1/3] types(withModifiers): explicit modifiers type --- packages/runtime-dom/src/directives/vOn.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/src/directives/vOn.ts b/packages/runtime-dom/src/directives/vOn.ts index 5a7d9e4af4a..6fbf85d709e 100644 --- a/packages/runtime-dom/src/directives/vOn.ts +++ b/packages/runtime-dom/src/directives/vOn.ts @@ -10,6 +10,18 @@ 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, @@ -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('.') From c265933d3bed8664a9029eed533c7554ab1030e7 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 3 May 2024 11:05:58 +0800 Subject: [PATCH 2/3] chore: update --- packages/runtime-dom/__tests__/directives/vOn.spec.ts | 2 +- packages/runtime-dom/src/directives/vOn.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/directives/vOn.spec.ts b/packages/runtime-dom/__tests__/directives/vOn.spec.ts index 03620f747e7..ef7ee346ba8 100644 --- a/packages/runtime-dom/__tests__/directives/vOn.spec.ts +++ b/packages/runtime-dom/__tests__/directives/vOn.spec.ts @@ -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') diff --git a/packages/runtime-dom/src/directives/vOn.ts b/packages/runtime-dom/src/directives/vOn.ts index 6fbf85d709e..2e40c146036 100644 --- a/packages/runtime-dom/src/directives/vOn.ts +++ b/packages/runtime-dom/src/directives/vOn.ts @@ -22,6 +22,7 @@ type ModifierGuardsKeys = | 'middle' | 'right' | 'exact' + | '' const modifierGuards: Record< string, From 12e4c926679d5ef9eba8d24045e83cd0da71a6cf Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Sat, 4 May 2024 07:53:39 +0800 Subject: [PATCH 3/3] chore: update --- packages/dts-test/defineComponent.test-d.tsx | 2 +- packages/runtime-dom/src/directives/vOn.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index 41646751b8b..d2a39be2621 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -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 => {}, []) ; }) diff --git a/packages/runtime-dom/src/directives/vOn.ts b/packages/runtime-dom/src/directives/vOn.ts index 2e40c146036..fd4010868ce 100644 --- a/packages/runtime-dom/src/directives/vOn.ts +++ b/packages/runtime-dom/src/directives/vOn.ts @@ -22,10 +22,9 @@ type ModifierGuardsKeys = | 'middle' | 'right' | 'exact' - | '' const modifierGuards: Record< - string, + ModifierGuardsKeys, (e: Event, modifiers: string[]) => void | boolean > = { stop: e => e.stopPropagation(),