diff --git a/packages/dts-test/appDirective.test-d.ts b/packages/dts-test/appDirective.test-d.ts new file mode 100644 index 00000000000..0d7707a7c19 --- /dev/null +++ b/packages/dts-test/appDirective.test-d.ts @@ -0,0 +1,14 @@ +import { createApp } from 'vue' +import { expectType } from './utils' + +const app = createApp({}) + +app.directive('custom', { + mounted(el, binding) { + expectType(el) + 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 8ba9429f447..0afae35f0d1 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -42,8 +42,8 @@ export interface App { mixin(mixin: ComponentOptions): this component(name: string): Component | undefined component(name: string, component: Component | DefineComponent): this - directive(name: string): Directive | undefined - directive(name: string, directive: Directive): this + directive(name: string): Directive | undefined + directive(name: string, directive: Directive): this mount( rootContainer: HostElement | string, isHydrate?: boolean, diff --git a/packages/runtime-core/src/compat/global.ts b/packages/runtime-core/src/compat/global.ts index 0379bb67e8e..1e4d206eae3 100644 --- a/packages/runtime-core/src/compat/global.ts +++ b/packages/runtime-core/src/compat/global.ts @@ -82,8 +82,11 @@ export type CompatVue = Pick & { component(name: string): Component | undefined component(name: string, component: Component): CompatVue - directive(name: string): Directive | undefined - directive(name: string, directive: Directive): CompatVue + directive(name: string): Directive | undefined + directive( + name: string, + directive: Directive + ): CompatVue compile(template: string): RenderFunction