diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index c5ac9d68a52..971b406cf01 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -16,7 +16,7 @@ import { ComponentPublicInstance } from './componentPublicInstance' import { Directive, validateDirectiveName } from './directives' -import { RootRenderFunction } from './renderer' +import { RendererElement, RootRenderFunction } from './renderer' import { InjectionKey } from './apiInject' import { warn } from './warning' import { createVNode, cloneVNode, VNode } from './vnode' @@ -196,7 +196,7 @@ export type CreateAppFunction = ( let uid = 0 -export function createAppAPI( +export function createAppAPI( render: RootRenderFunction, hydrate?: RootHydrateFunction ): CreateAppFunction { diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 18c3352b002..eb80cd495f6 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -21,6 +21,7 @@ import { ComponentPublicInstance } from './componentPublicInstance' import { mapCompatDirectiveHook } from './compat/customDirective' import { pauseTracking, resetTracking } from '@vue/reactivity' import { traverse } from './apiWatch' +import { RendererElement } from './renderer' export interface DirectiveBinding { instance: ComponentPublicInstance | null @@ -31,7 +32,11 @@ export interface DirectiveBinding { dir: ObjectDirective } -export type DirectiveHook | null, V = any> = ( +export type DirectiveHook< + T extends RendererElement = any, + Prev = VNode | null, + V = any +> = ( el: T, binding: DirectiveBinding, vnode: VNode, @@ -43,7 +48,7 @@ export type SSRDirectiveHook = ( vnode: VNode ) => Data | undefined -export interface ObjectDirective { +export interface ObjectDirective { created?: DirectiveHook beforeMount?: DirectiveHook mounted?: DirectiveHook @@ -55,9 +60,12 @@ export interface ObjectDirective { deep?: boolean } -export type FunctionDirective = DirectiveHook +export type FunctionDirective< + T extends RendererElement = any, + V = any +> = DirectiveHook -export type Directive = +export type Directive = | ObjectDirective | FunctionDirective diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index 413355508b9..086dcafe034 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -90,7 +90,7 @@ export type RootRenderFunction = ( export interface RendererOptions< HostNode = RendererNode, - HostElement = RendererElement + HostElement extends RendererElement = RendererElement > { patchProp( el: HostElement, @@ -145,7 +145,7 @@ export interface RendererElement extends RendererNode {} // to optimize bundle size. export interface RendererInternals< HostNode = RendererNode, - HostElement = RendererElement + HostElement extends RendererElement = RendererElement > { p: PatchFn um: UnmountFn @@ -295,7 +295,7 @@ export const queuePostRenderEffect = __FEATURE_SUSPENSE__ */ export function createRenderer< HostNode = RendererNode, - HostElement = RendererElement + HostElement extends RendererElement = RendererElement >(options: RendererOptions) { return baseCreateRenderer(options) } @@ -312,7 +312,7 @@ export function createHydrationRenderer( // overload 1: no hydration function baseCreateRenderer< HostNode = RendererNode, - HostElement = RendererElement + HostElement extends RendererElement = RendererElement >(options: RendererOptions): Renderer // overload 2: with hydration diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index a69b34ed941..2c0e5e1ccaa 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -133,7 +133,7 @@ export type VNodeNormalizedChildren = export interface VNode< HostNode = RendererNode, - HostElement = RendererElement, + HostElement extends RendererElement = RendererElement, ExtraProps = { [key: string]: any } > { /** @@ -613,7 +613,7 @@ export function guardReactiveProps(props: (Data & VNodeProps) | null) { : props } -export function cloneVNode( +export function cloneVNode( vnode: VNode, extraProps?: (Data & VNodeProps) | null, mergeRef = false