mirror of https://github.com/vuejs/core.git
types: improve app.directive type generics (#11926)
This commit is contained in:
parent
aa5dafd2b5
commit
1bad606eb3
|
@ -3,12 +3,17 @@ import { expectType } from './utils'
|
||||||
|
|
||||||
const app = createApp({})
|
const app = createApp({})
|
||||||
|
|
||||||
app.directive<HTMLElement, string>('custom', {
|
app.directive<HTMLElement, string, 'prevent' | 'stop', 'arg1' | 'arg2'>(
|
||||||
mounted(el, binding) {
|
'custom',
|
||||||
expectType<HTMLElement>(el)
|
{
|
||||||
expectType<string>(binding.value)
|
mounted(el, binding) {
|
||||||
|
expectType<HTMLElement>(el)
|
||||||
|
expectType<string>(binding.value)
|
||||||
|
expectType<{ prevent: boolean; stop: boolean }>(binding.modifiers)
|
||||||
|
expectType<'arg1' | 'arg2'>(binding.arg!)
|
||||||
|
|
||||||
// @ts-expect-error not any
|
// @ts-expect-error not any
|
||||||
expectType<number>(binding.value)
|
expectType<number>(binding.value)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
)
|
||||||
|
|
|
@ -46,8 +46,23 @@ export interface App<HostElement = any> {
|
||||||
name: string,
|
name: string,
|
||||||
component: T,
|
component: T,
|
||||||
): this
|
): this
|
||||||
directive<T = any, V = any>(name: string): Directive<T, V> | undefined
|
directive<
|
||||||
directive<T = any, V = any>(name: string, directive: Directive<T, V>): this
|
HostElement = any,
|
||||||
|
Value = any,
|
||||||
|
Modifiers extends string = string,
|
||||||
|
Arg extends string = string,
|
||||||
|
>(
|
||||||
|
name: string,
|
||||||
|
): Directive<HostElement, Value, Modifiers, Arg> | undefined
|
||||||
|
directive<
|
||||||
|
HostElement = any,
|
||||||
|
Value = any,
|
||||||
|
Modifiers extends string = string,
|
||||||
|
Arg extends string = string,
|
||||||
|
>(
|
||||||
|
name: string,
|
||||||
|
directive: Directive<HostElement, Value, Modifiers, Arg>,
|
||||||
|
): this
|
||||||
mount(
|
mount(
|
||||||
rootContainer: HostElement | string,
|
rootContainer: HostElement | string,
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue