From: Carlos Rodrigues Date: Mon, 23 Oct 2023 15:40:06 +0000 (+0100) Subject: fix(types): improve `h` overload to support union of string and component (#5432) X-Git-Tag: v3.3.7~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16ecb44c89cd8299a3b8de33cccc2e2cc36f065b;p=thirdparty%2Fvuejs%2Fcore.git fix(types): improve `h` overload to support union of string and component (#5432) fix #5431 --- diff --git a/packages/dts-test/h.test-d.ts b/packages/dts-test/h.test-d.ts index 5c700800e9..f2e984b49b 100644 --- a/packages/dts-test/h.test-d.ts +++ b/packages/dts-test/h.test-d.ts @@ -1,6 +1,7 @@ import { h, defineComponent, + DefineComponent, ref, Fragment, Teleport, @@ -231,3 +232,18 @@ describe('resolveComponent should work', () => { message: '1' }) }) + +// #5431 +describe('h should work with multiple types', () => { + const serializers = { + Paragraph: 'p', + Component: {} as Component, + DefineComponent: {} as DefineComponent + } + + const sampleComponent = serializers['' as keyof typeof serializers] + + h(sampleComponent) + h(sampleComponent, {}) + h(sampleComponent, {}, []) +}) diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index 73b27107b8..4ca90262f2 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -174,6 +174,14 @@ export function h

( children?: RawChildren | RawSlots ): VNode +// catch all types +export function h(type: string | Component, children?: RawChildren): VNode +export function h

( + type: string | Component

, + props?: (RawProps & P) | ({} extends P ? null : never), + children?: RawChildren | RawSlots +): VNode + // Actual implementation export function h(type: any, propsOrChildren?: any, children?: any): VNode { const l = arguments.length