Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(runtime-core): Add h overload to support string|Component|DefineComponent types #5432

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 or types
yyx990803 marked this conversation as resolved.
Show resolved Hide resolved
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