From: Buer Yang <1244476905@qq.com> Date: Wed, 19 Mar 2025 03:38:59 +0000 (+0800) Subject: fix(types): the directive's modifiers should be optional (#12605) X-Git-Tag: v3.5.14~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10e54dcc86a7967f3196d96200bcbd1d3d42082f;p=thirdparty%2Fvuejs%2Fcore.git 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 --- diff --git a/packages-private/dts-test/appDirective.test-d.ts b/packages-private/dts-test/appDirective.test-d.ts index fb655a039d..59101c22ec 100644 --- a/packages-private/dts-test/appDirective.test-d.ts +++ b/packages-private/dts-test/appDirective.test-d.ts @@ -9,7 +9,7 @@ app.directive( mounted(el, binding) { expectType(el) expectType(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 diff --git a/packages-private/dts-test/directives.test-d.ts b/packages-private/dts-test/directives.test-d.ts index 5b87ebf71e..6a478b673d 100644 --- a/packages-private/dts-test/directives.test-d.ts +++ b/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> }>(testDirective()) expectType<{ diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index f6a33f5a28..5897b39df8 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -111,7 +111,9 @@ export type Directive< | ObjectDirective | FunctionDirective -export type DirectiveModifiers = Record +export type DirectiveModifiers = Partial< + Record +> export function validateDirectiveName(name: string): void { if (isBuiltInDirective(name)) {