]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: improve directive hook argument types
authorEvan You <yyx990803@gmail.com>
Wed, 18 Mar 2020 16:30:20 +0000 (12:30 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 18 Mar 2020 16:30:26 +0000 (12:30 -0400)
packages/runtime-core/src/directives.ts
packages/runtime-dom/src/directives/vModel.ts

index 434ab83f8a19dce275f80fd28cf0520d26b9b796..f5e0eb1ba0b62daefee5ab5483fb70ab3181a6a0 100644 (file)
@@ -28,11 +28,11 @@ export interface DirectiveBinding {
   dir: ObjectDirective
 }
 
-export type DirectiveHook<T = any> = (
+export type DirectiveHook<T = any, Prev = VNode<any, T> | null> = (
   el: T,
   binding: DirectiveBinding,
   vnode: VNode<any, T>,
-  prevVNode: VNode<any, T> | null
+  prevVNode: Prev
 ) => void
 
 export type SSRDirectiveHook = (
@@ -41,12 +41,12 @@ export type SSRDirectiveHook = (
 ) => Data | undefined
 
 export interface ObjectDirective<T = any> {
-  beforeMount?: DirectiveHook<T>
-  mounted?: DirectiveHook<T>
-  beforeUpdate?: DirectiveHook<T>
-  updated?: DirectiveHook<T>
-  beforeUnmount?: DirectiveHook<T>
-  unmounted?: DirectiveHook<T>
+  beforeMount?: DirectiveHook<T, null>
+  mounted?: DirectiveHook<T, null>
+  beforeUpdate?: DirectiveHook<T, VNode<any, T>>
+  updated?: DirectiveHook<T, VNode<any, T>>
+  beforeUnmount?: DirectiveHook<T, null>
+  unmounted?: DirectiveHook<T, null>
   getSSRProps?: SSRDirectiveHook
 }
 
index 4633648959754cfaa0bbc9b9449cb3a049663ce5..703ee7221e4bccf5b9c92a2dd1aa9a80ead97be6 100644 (file)
@@ -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)
 }