Skip to content

Commit 10e54dc

Browse files
noootwoedison1105
andauthored
fix(types): the directive's modifiers should be optional (#12605)
* fix(types): the directive's modifiers should be optional * fix: test --------- Co-authored-by: edison <[email protected]>
1 parent 4fea167 commit 10e54dc

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

packages-private/dts-test/appDirective.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ app.directive<HTMLElement, string, 'prevent' | 'stop', 'arg1' | 'arg2'>(
99
mounted(el, binding) {
1010
expectType<HTMLElement>(el)
1111
expectType<string>(binding.value)
12-
expectType<{ prevent: boolean; stop: boolean }>(binding.modifiers)
12+
expectType<{ prevent?: boolean; stop?: boolean }>(binding.modifiers)
1313
expectType<'arg1' | 'arg2'>(binding.arg!)
1414

1515
// @ts-expect-error not any

packages-private/dts-test/directives.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('custom', () => {
2929
value: number
3030
oldValue: number | null
3131
arg?: 'Arg'
32-
modifiers: Record<'a' | 'b', boolean>
32+
modifiers: Partial<Record<'a' | 'b', boolean>>
3333
}>(testDirective<number, 'a' | 'b', 'Arg'>())
3434

3535
expectType<{

packages/runtime-core/src/directives.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export type Directive<
111111
| ObjectDirective<HostElement, Value, Modifiers, Arg>
112112
| FunctionDirective<HostElement, Value, Modifiers, Arg>
113113

114-
export type DirectiveModifiers<K extends string = string> = Record<K, boolean>
114+
export type DirectiveModifiers<K extends string = string> = Partial<
115+
Record<K, boolean>
116+
>
115117

116118
export function validateDirectiveName(name: string): void {
117119
if (isBuiltInDirective(name)) {

0 commit comments

Comments
 (0)