Skip to content

Commit 08edbb0

Browse files
committed
types(runtime-core): support type with directive value
fix vuejs#998
1 parent 6fefeaf commit 08edbb0

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

packages/runtime-core/src/directives.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ import { currentRenderingInstance } from './componentRenderUtils'
1919
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
2020
import { ComponentPublicInstance } from './componentProxy'
2121

22-
export interface DirectiveBinding {
22+
export interface DirectiveBinding<V = any> {
2323
instance: ComponentPublicInstance | null
24-
value: any
25-
oldValue: any
24+
value: V
25+
oldValue: V | null
2626
arg?: string
2727
modifiers: DirectiveModifiers
28-
dir: ObjectDirective
28+
dir: ObjectDirective<any, V>
2929
}
3030

31-
export type DirectiveHook<T = any, Prev = VNode<any, T> | null> = (
31+
export type DirectiveHook<T = any, Prev = VNode<any, T> | null, V = any> = (
3232
el: T,
33-
binding: DirectiveBinding,
33+
binding: DirectiveBinding<V>,
3434
vnode: VNode<any, T>,
3535
prevVNode: Prev
3636
) => void
@@ -40,19 +40,21 @@ export type SSRDirectiveHook = (
4040
vnode: VNode
4141
) => Data | undefined
4242

43-
export interface ObjectDirective<T = any> {
44-
beforeMount?: DirectiveHook<T, null>
45-
mounted?: DirectiveHook<T, null>
46-
beforeUpdate?: DirectiveHook<T, VNode<any, T>>
47-
updated?: DirectiveHook<T, VNode<any, T>>
48-
beforeUnmount?: DirectiveHook<T, null>
49-
unmounted?: DirectiveHook<T, null>
43+
export interface ObjectDirective<T = any, V = any> {
44+
beforeMount?: DirectiveHook<T, null, V>
45+
mounted?: DirectiveHook<T, null, V>
46+
beforeUpdate?: DirectiveHook<T, VNode<any, T>, V>
47+
updated?: DirectiveHook<T, VNode<any, T>, V>
48+
beforeUnmount?: DirectiveHook<T, null, V>
49+
unmounted?: DirectiveHook<T, null, V>
5050
getSSRProps?: SSRDirectiveHook
5151
}
5252

53-
export type FunctionDirective<T = any> = DirectiveHook<T>
53+
export type FunctionDirective<T = any, V = any> = DirectiveHook<T, any, V>
5454

55-
export type Directive<T = any> = ObjectDirective<T> | FunctionDirective<T>
55+
export type Directive<T = any, V = any> =
56+
| ObjectDirective<T, V>
57+
| FunctionDirective<T, V>
5658

5759
export type DirectiveModifiers = Record<string, boolean>
5860

0 commit comments

Comments
 (0)