Skip to content

Commit 16ecb44

Browse files
authored
fix(types): improve h overload to support union of string and component (#5432)
fix #5431
1 parent f36c49f commit 16ecb44

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: packages/dts-test/h.test-d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
h,
33
defineComponent,
4+
DefineComponent,
45
ref,
56
Fragment,
67
Teleport,
@@ -231,3 +232,18 @@ describe('resolveComponent should work', () => {
231232
message: '1'
232233
})
233234
})
235+
236+
// #5431
237+
describe('h should work with multiple types', () => {
238+
const serializers = {
239+
Paragraph: 'p',
240+
Component: {} as Component,
241+
DefineComponent: {} as DefineComponent
242+
}
243+
244+
const sampleComponent = serializers['' as keyof typeof serializers]
245+
246+
h(sampleComponent)
247+
h(sampleComponent, {})
248+
h(sampleComponent, {}, [])
249+
})

Diff for: packages/runtime-core/src/h.ts

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ export function h<P>(
174174
children?: RawChildren | RawSlots
175175
): VNode
176176

177+
// catch all types
178+
export function h(type: string | Component, children?: RawChildren): VNode
179+
export function h<P>(
180+
type: string | Component<P>,
181+
props?: (RawProps & P) | ({} extends P ? null : never),
182+
children?: RawChildren | RawSlots
183+
): VNode
184+
177185
// Actual implementation
178186
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
179187
const l = arguments.length

0 commit comments

Comments
 (0)