From 71bc13575f0805bf33744db7f5edb053e1642d3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Thu, 7 Dec 2023 10:46:34 +0800 Subject: [PATCH] types(runtime-vapor): add modifiers & argument type --- packages/runtime-vapor/src/directives.ts | 61 ++++++++++++++++-------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/runtime-vapor/src/directives.ts b/packages/runtime-vapor/src/directives.ts index 7060a92f4f..70833e9732 100644 --- a/packages/runtime-vapor/src/directives.ts +++ b/packages/runtime-vapor/src/directives.ts @@ -1,41 +1,62 @@ import { isFunction } from '@vue/shared' import { currentInstance, type ComponentInternalInstance } from './component' -import type { DirectiveModifiers } from '@vue/runtime-dom' -export interface DirectiveBinding { +export type DirectiveModifiers = Record + +export interface DirectiveBinding< + V = any, + A = string, + M extends string = string, +> { instance: ComponentInternalInstance | null value: V oldValue: V | null - arg?: string - modifiers?: DirectiveModifiers + arg?: A + modifiers?: DirectiveModifiers dir: ObjectDirective } -export type DirectiveHook = ( - node: T, - binding: DirectiveBinding, -) => void +export type DirectiveHook< + T = any | null, + V = any, + A = string, + M extends string = string, +> = (node: T, binding: DirectiveBinding) => void // create node -> `created` -> node operation -> `beforeMount` -> node mounted -> `mounted` // effect update -> `beforeUpdate` -> node updated -> `updated` // `beforeUnmount`-> node unmount -> `unmounted` -export interface ObjectDirective { - created?: DirectiveHook - beforeMount?: DirectiveHook - mounted?: DirectiveHook - // beforeUpdate?: DirectiveHook - // updated?: DirectiveHook - beforeUnmount?: DirectiveHook - unmounted?: DirectiveHook +export interface ObjectDirective< + T = any, + V = any, + A = string, + M extends string = string, +> { + created?: DirectiveHook + beforeMount?: DirectiveHook + mounted?: DirectiveHook + // beforeUpdate?: DirectiveHook + // updated?: DirectiveHook + beforeUnmount?: DirectiveHook + unmounted?: DirectiveHook // getSSRProps?: SSRDirectiveHook // deep?: boolean } export type DirectiveHookName = Exclude -export type FunctionDirective = DirectiveHook -export type Directive = - | ObjectDirective - | FunctionDirective +export type FunctionDirective< + T = any, + V = any, + A = string, + M extends string = string, +> = DirectiveHook + +export type Directive< + T = any, + V = any, + A = string, + M extends string = string, +> = ObjectDirective | FunctionDirective export type DirectiveArguments = Array< | [Directive | undefined] -- 2.47.2