From 419b86d1908f2a0521e6a7eafcbee764e9ee59a0 Mon Sep 17 00:00:00 2001 From: underfin <2218301630@qq.com> Date: Fri, 12 Jun 2020 04:37:14 +0800 Subject: [PATCH] feat(types): support typing directive value via generic argument (#1007) close #998 --- packages/runtime-core/src/directives.ts | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 8626396efe9..478ca6bb46b 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -19,18 +19,18 @@ import { currentRenderingInstance } from './componentRenderUtils' import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling' import { ComponentPublicInstance } from './componentProxy' -export interface DirectiveBinding { +export interface DirectiveBinding { instance: ComponentPublicInstance | null - value: any - oldValue: any + value: V + oldValue: V | null arg?: string modifiers: DirectiveModifiers - dir: ObjectDirective + dir: ObjectDirective } -export type DirectiveHook | null> = ( +export type DirectiveHook | null, V = any> = ( el: T, - binding: DirectiveBinding, + binding: DirectiveBinding, vnode: VNode, prevVNode: Prev ) => void @@ -40,19 +40,21 @@ export type SSRDirectiveHook = ( vnode: VNode ) => Data | undefined -export interface ObjectDirective { - beforeMount?: DirectiveHook - mounted?: DirectiveHook - beforeUpdate?: DirectiveHook> - updated?: DirectiveHook> - beforeUnmount?: DirectiveHook - unmounted?: DirectiveHook +export interface ObjectDirective { + beforeMount?: DirectiveHook + mounted?: DirectiveHook + beforeUpdate?: DirectiveHook, V> + updated?: DirectiveHook, V> + beforeUnmount?: DirectiveHook + unmounted?: DirectiveHook getSSRProps?: SSRDirectiveHook } -export type FunctionDirective = DirectiveHook +export type FunctionDirective = DirectiveHook -export type Directive = ObjectDirective | FunctionDirective +export type Directive = + | ObjectDirective + | FunctionDirective export type DirectiveModifiers = Record