From be91b43564574839ff0a6d9bd9b1f6bdbdbd96c2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 18 Mar 2020 12:30:20 -0400 Subject: [PATCH] types: improve directive hook argument types --- packages/runtime-core/src/directives.ts | 16 ++++++++-------- packages/runtime-dom/src/directives/vModel.ts | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 434ab83f..f5e0eb1b 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -28,11 +28,11 @@ export interface DirectiveBinding { dir: ObjectDirective } -export type DirectiveHook = ( +export type DirectiveHook | null> = ( el: T, binding: DirectiveBinding, vnode: VNode, - prevVNode: VNode | null + prevVNode: Prev ) => void export type SSRDirectiveHook = ( @@ -41,12 +41,12 @@ export type SSRDirectiveHook = ( ) => Data | undefined export interface ObjectDirective { - beforeMount?: DirectiveHook - mounted?: DirectiveHook - beforeUpdate?: DirectiveHook - updated?: DirectiveHook - beforeUnmount?: DirectiveHook - unmounted?: DirectiveHook + beforeMount?: DirectiveHook + mounted?: DirectiveHook + beforeUpdate?: DirectiveHook> + updated?: DirectiveHook> + beforeUnmount?: DirectiveHook + unmounted?: DirectiveHook getSSRProps?: SSRDirectiveHook } diff --git a/packages/runtime-dom/src/directives/vModel.ts b/packages/runtime-dom/src/directives/vModel.ts index 46336489..703ee722 100644 --- a/packages/runtime-dom/src/directives/vModel.ts +++ b/packages/runtime-dom/src/directives/vModel.ts @@ -1,6 +1,7 @@ import { ObjectDirective, VNode, + DirectiveHook, DirectiveBinding, warn } from '@vue/runtime-core' @@ -240,7 +241,7 @@ function callModelHook( modelToUse = vModelText } } - const fn = modelToUse[hook] + const fn = modelToUse[hook] as DirectiveHook fn && fn(el, binding, vnode, prevVNode) }