]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): the directive's modifiers should be optional (#12605)
authorBuer Yang <1244476905@qq.com>
Wed, 19 Mar 2025 03:38:59 +0000 (11:38 +0800)
committerGitHub <noreply@github.com>
Wed, 19 Mar 2025 03:38:59 +0000 (11:38 +0800)
* fix(types): the directive's modifiers should be optional

* fix: test

---------

Co-authored-by: edison <daiwei521@126.com>
packages-private/dts-test/appDirective.test-d.ts
packages-private/dts-test/directives.test-d.ts
packages/runtime-core/src/directives.ts

index fb655a039d58c7f3e7b59e15b60d295906fa4acc..59101c22ec8f2020018f6a9e5c691eea9365186b 100644 (file)
@@ -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
index 5b87ebf71e5281d5ebad91343dfdd6b01e35cb7a..6a478b673d95b7966b5c63adc5e61b1ca92f2b2b 100644 (file)
@@ -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<{
index f6a33f5a289159837bd3e9f7bcca62358b42d3fa..5897b39df82f8bbc6490f849fe10638df748de9c 100644 (file)
@@ -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)) {