Skip to content

Commit

Permalink
feat(types): support passing generics when registering global directi…
Browse files Browse the repository at this point in the history
…ves (#9660)
  • Loading branch information
mitjans authored Dec 11, 2023
1 parent fd0b6ba commit a41409e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/dts-test/appDirective.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createApp } from 'vue'
import { expectType } from './utils'

const app = createApp({})

app.directive<HTMLElement, string>('custom', {
mounted(el, binding) {
expectType<HTMLElement>(el)
expectType<string>(binding.value)

// @ts-expect-error not any
expectType<number>(binding.value)
}
})
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export interface App<HostElement = any> {
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<T = any, V = any>(name: string): Directive<T, V> | undefined
directive<T = any, V = any>(name: string, directive: Directive<T, V>): this
mount(
rootContainer: HostElement | string,
isHydrate?: boolean,
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-core/src/compat/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {

component(name: string): Component | undefined
component(name: string, component: Component): CompatVue
directive(name: string): Directive | undefined
directive(name: string, directive: Directive): CompatVue
directive<T = any, V = any>(name: string): Directive<T, V> | undefined
directive<T = any, V = any>(
name: string,
directive: Directive<T, V>
): CompatVue

compile(template: string): RenderFunction

Expand Down

0 comments on commit a41409e

Please sign in to comment.