From: btea <2356281422@qq.com> Date: Mon, 6 May 2024 22:23:04 +0000 (+0800) Subject: refactor(types): use explicit modifiers type (#10856) X-Git-Tag: v3.4.27~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=481b1b6f38a00231ad38ea5a86758ffdd8cb04a0;p=thirdparty%2Fvuejs%2Fcore.git refactor(types): use explicit modifiers type (#10856) --- diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index 41646751b8..d2a39be262 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/__tests__/directives/vOn.spec.ts b/packages/runtime-dom/__tests__/directives/vOn.spec.ts index 03620f747e..ef7ee346ba 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 5a7d9e4af4..fd4010868c 100644 --- a/packages/runtime-dom/src/directives/vOn.ts +++ b/packages/runtime-dom/src/directives/vOn.ts @@ -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('.')