diff --git a/packages-private/dts-test/appDirective.test-d.ts b/packages-private/dts-test/appDirective.test-d.ts index 1ac5f64d19a..fb655a039d5 100644 --- a/packages-private/dts-test/appDirective.test-d.ts +++ b/packages-private/dts-test/appDirective.test-d.ts @@ -3,12 +3,17 @@ import { expectType } from './utils' const app = createApp({}) -app.directive('custom', { - mounted(el, binding) { - expectType(el) - expectType(binding.value) +app.directive( + 'custom', + { + mounted(el, binding) { + expectType(el) + expectType(binding.value) + expectType<{ prevent: boolean; stop: boolean }>(binding.modifiers) + expectType<'arg1' | 'arg2'>(binding.arg!) - // @ts-expect-error not any - expectType(binding.value) + // @ts-expect-error not any + expectType(binding.value) + }, }, -}) +) diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index 7c016e12fcf..3d53716de08 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -46,8 +46,23 @@ export interface App { name: string, component: T, ): this - directive(name: string): Directive | undefined - directive(name: string, directive: Directive): this + directive< + HostElement = any, + Value = any, + Modifiers extends string = string, + Arg extends string = string, + >( + name: string, + ): Directive | undefined + directive< + HostElement = any, + Value = any, + Modifiers extends string = string, + Arg extends string = string, + >( + name: string, + directive: Directive, + ): this mount( rootContainer: HostElement | string, /**