Skip to content

Commit 481b1b6

Browse files
authored
refactor(types): use explicit modifiers type (#10856)
1 parent 8373350 commit 481b1b6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/dts-test/defineComponent.test-d.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ describe('should work when props type is incompatible with setup returned type '
15011501

15021502
describe('withKeys and withModifiers as pro', () => {
15031503
const onKeydown = withKeys(e => {}, [''])
1504-
const onClick = withModifiers(e => {}, [''])
1504+
const onClick = withModifiers(e => {}, [])
15051505
;<input onKeydown={onKeydown} onClick={onClick} />
15061506
})
15071507

packages/runtime-dom/__tests__/directives/vOn.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('runtime-dom: v-on directive', () => {
4343
})
4444

4545
test('it should support key modifiers and system modifiers', () => {
46-
const keyNames = ['ctrl', 'shift', 'meta', 'alt']
46+
const keyNames = ['ctrl', 'shift', 'meta', 'alt'] as const
4747

4848
keyNames.forEach(keyName => {
4949
const el = document.createElement('div')

packages/runtime-dom/src/directives/vOn.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@ import { hyphenate, isArray } from '@vue/shared'
1010
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']
1111

1212
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent
13+
type ModifierGuardsKeys =
14+
| 'stop'
15+
| 'prevent'
16+
| 'self'
17+
| 'ctrl'
18+
| 'shift'
19+
| 'alt'
20+
| 'meta'
21+
| 'left'
22+
| 'middle'
23+
| 'right'
24+
| 'exact'
1325

1426
const modifierGuards: Record<
15-
string,
27+
ModifierGuardsKeys,
1628
(e: Event, modifiers: string[]) => void | boolean
1729
> = {
1830
stop: e => e.stopPropagation(),
@@ -36,7 +48,7 @@ export const withModifiers = <
3648
T extends (event: Event, ...args: unknown[]) => any,
3749
>(
3850
fn: T & { _withMods?: { [key: string]: T } },
39-
modifiers: string[],
51+
modifiers: ModifierGuardsKeys[],
4052
) => {
4153
const cache = fn._withMods || (fn._withMods = {})
4254
const cacheKey = modifiers.join('.')

0 commit comments

Comments
 (0)