Skip to content

Commit a41409e

Browse files
authoredDec 11, 2023
feat(types): support passing generics when registering global directives (#9660)
1 parent fd0b6ba commit a41409e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
 
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createApp } from 'vue'
2+
import { expectType } from './utils'
3+
4+
const app = createApp({})
5+
6+
app.directive<HTMLElement, string>('custom', {
7+
mounted(el, binding) {
8+
expectType<HTMLElement>(el)
9+
expectType<string>(binding.value)
10+
11+
// @ts-expect-error not any
12+
expectType<number>(binding.value)
13+
}
14+
})

‎packages/runtime-core/src/apiCreateApp.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export interface App<HostElement = any> {
4242
mixin(mixin: ComponentOptions): this
4343
component(name: string): Component | undefined
4444
component(name: string, component: Component | DefineComponent): this
45-
directive(name: string): Directive | undefined
46-
directive(name: string, directive: Directive): this
45+
directive<T = any, V = any>(name: string): Directive<T, V> | undefined
46+
directive<T = any, V = any>(name: string, directive: Directive<T, V>): this
4747
mount(
4848
rootContainer: HostElement | string,
4949
isHydrate?: boolean,

‎packages/runtime-core/src/compat/global.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
8282

8383
component(name: string): Component | undefined
8484
component(name: string, component: Component): CompatVue
85-
directive(name: string): Directive | undefined
86-
directive(name: string, directive: Directive): CompatVue
85+
directive<T = any, V = any>(name: string): Directive<T, V> | undefined
86+
directive<T = any, V = any>(
87+
name: string,
88+
directive: Directive<T, V>
89+
): CompatVue
8790

8891
compile(template: string): RenderFunction
8992

0 commit comments

Comments
 (0)
Please sign in to comment.