From: underfin <2218301630@qq.com> Date: Thu, 11 Jun 2020 20:37:14 +0000 (+0800) Subject: feat(types): support typing directive value via generic argument (#1007) X-Git-Tag: v3.0.0-beta.15~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=419b86d1908f2a0521e6a7eafcbee764e9ee59a0;p=thirdparty%2Fvuejs%2Fcore.git feat(types): support typing directive value via generic argument (#1007) close #998 --- diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 8626396efe..478ca6bb46 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