Просмотр исходного кода

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 <daiwei521@126.com>
Buer Yang 1 год назад
Родитель
Сommit
10e54dcc86

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

@@ -9,7 +9,7 @@ app.directive<HTMLElement, string, 'prevent' | 'stop', 'arg1' | 'arg2'>(
     mounted(el, binding) {
       expectType<HTMLElement>(el)
       expectType<string>(binding.value)
-      expectType<{ prevent: boolean; stop: boolean }>(binding.modifiers)
+      expectType<{ prevent?: boolean; stop?: boolean }>(binding.modifiers)
       expectType<'arg1' | 'arg2'>(binding.arg!)
 
       // @ts-expect-error not any

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

@@ -29,7 +29,7 @@ describe('custom', () => {
     value: number
     oldValue: number | null
     arg?: 'Arg'
-    modifiers: Record<'a' | 'b', boolean>
+    modifiers: Partial<Record<'a' | 'b', boolean>>
   }>(testDirective<number, 'a' | 'b', 'Arg'>())
 
   expectType<{

+ 3 - 1
packages/runtime-core/src/directives.ts

@@ -111,7 +111,9 @@ export type Directive<
   | ObjectDirective<HostElement, Value, Modifiers, Arg>
   | FunctionDirective<HostElement, Value, Modifiers, Arg>
 
-export type DirectiveModifiers<K extends string = string> = Record<K, boolean>
+export type DirectiveModifiers<K extends string = string> = Partial<
+  Record<K, boolean>
+>
 
 export function validateDirectiveName(name: string): void {
   if (isBuiltInDirective(name)) {