From 10e54dcc86a7967f3196d96200bcbd1d3d42082f Mon Sep 17 00:00:00 2001 From: Buer Yang <1244476905@qq.com> Date: Wed, 19 Mar 2025 11:38:59 +0800 Subject: [PATCH] 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 --- packages-private/dts-test/appDirective.test-d.ts | 2 +- packages-private/dts-test/directives.test-d.ts | 2 +- packages/runtime-core/src/directives.ts | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages-private/dts-test/appDirective.test-d.ts b/packages-private/dts-test/appDirective.test-d.ts index fb655a039..59101c22e 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 5b87ebf71..6a478b673 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 f6a33f5a2..5897b39df 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)) {