types: improve directive hook argument types

This commit is contained in:
Evan You 2020-03-18 12:30:20 -04:00
parent aa4ab39c1a
commit be91b43564
2 changed files with 10 additions and 9 deletions

View File

@ -28,11 +28,11 @@ export interface DirectiveBinding {
dir: ObjectDirective dir: ObjectDirective
} }
export type DirectiveHook<T = any> = ( export type DirectiveHook<T = any, Prev = VNode<any, T> | null> = (
el: T, el: T,
binding: DirectiveBinding, binding: DirectiveBinding,
vnode: VNode<any, T>, vnode: VNode<any, T>,
prevVNode: VNode<any, T> | null prevVNode: Prev
) => void ) => void
export type SSRDirectiveHook = ( export type SSRDirectiveHook = (
@ -41,12 +41,12 @@ export type SSRDirectiveHook = (
) => Data | undefined ) => Data | undefined
export interface ObjectDirective<T = any> { export interface ObjectDirective<T = any> {
beforeMount?: DirectiveHook<T> beforeMount?: DirectiveHook<T, null>
mounted?: DirectiveHook<T> mounted?: DirectiveHook<T, null>
beforeUpdate?: DirectiveHook<T> beforeUpdate?: DirectiveHook<T, VNode<any, T>>
updated?: DirectiveHook<T> updated?: DirectiveHook<T, VNode<any, T>>
beforeUnmount?: DirectiveHook<T> beforeUnmount?: DirectiveHook<T, null>
unmounted?: DirectiveHook<T> unmounted?: DirectiveHook<T, null>
getSSRProps?: SSRDirectiveHook getSSRProps?: SSRDirectiveHook
} }

View File

@ -1,6 +1,7 @@
import { import {
ObjectDirective, ObjectDirective,
VNode, VNode,
DirectiveHook,
DirectiveBinding, DirectiveBinding,
warn warn
} from '@vue/runtime-core' } from '@vue/runtime-core'
@ -240,7 +241,7 @@ function callModelHook(
modelToUse = vModelText modelToUse = vModelText
} }
} }
const fn = modelToUse[hook] const fn = modelToUse[hook] as DirectiveHook
fn && fn(el, binding, vnode, prevVNode) fn && fn(el, binding, vnode, prevVNode)
} }