From 87f69aa26f195390b948fbb0ff62cf954b58c82c Mon Sep 17 00:00:00 2001 From: Shiluo34 Date: Tue, 11 Oct 2022 13:36:50 +0800 Subject: [PATCH] fix(types): support Ref and function types in tsx ref attribute (#12759) fix #12758 --- types/test/v3/tsx-test.tsx | 7 ++++++- types/vnode.d.ts | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/types/test/v3/tsx-test.tsx b/types/test/v3/tsx-test.tsx index 16a767ac..286c1699 100644 --- a/types/test/v3/tsx-test.tsx +++ b/types/test/v3/tsx-test.tsx @@ -1,4 +1,4 @@ -import { VNode, defineComponent } from '../../index' +import { VNode, defineComponent, ref } from '../../index' import { expectType } from '../utils' expectType(
) @@ -22,6 +22,11 @@ expectError(
) expectType(
) expectType(
) +// allow Ref type type on arbitrary element +const fooRef = ref() +expectType(
) +expectType(
{fooRef.value = el as HTMLElement}} />) + expectType( { diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 7a543f0a..29bdb398 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,5 +1,7 @@ import { Vue } from './vue' import { DirectiveFunction, DirectiveOptions } from './options' +import { Ref } from './v3-generated' +import { ComponentPublicInstance } from './v3-component-public-instance' /** * For extending allowed non-declared props on components in TSX @@ -65,11 +67,19 @@ export interface VNodeComponentOptions { tag?: string } +export type VNodeRef = + | string + | Ref + | (( + ref: Element | ComponentPublicInstance | null, + refs: Record + ) => void) + export interface VNodeData { key?: string | number slot?: string scopedSlots?: { [key: string]: ScopedSlot | undefined } - ref?: string + ref?: VNodeRef refInFor?: boolean tag?: string staticClass?: string