Skip to content

Commit

Permalink
fix(types): improve h overload to support union of string and compo…
Browse files Browse the repository at this point in the history
…nent (#5432)

fix #5431
  • Loading branch information
pikax authored Oct 23, 2023
1 parent f36c49f commit 16ecb44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/dts-test/h.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
h,
defineComponent,
DefineComponent,
ref,
Fragment,
Teleport,
Expand Down Expand Up @@ -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, {}, [])
})
8 changes: 8 additions & 0 deletions packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ export function h<P>(
children?: RawChildren | RawSlots
): VNode

// catch all types
export function h(type: string | Component, children?: RawChildren): VNode
export function h<P>(
type: string | Component<P>,
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
Expand Down

0 comments on commit 16ecb44

Please sign in to comment.