mirror of https://github.com/vuejs/core.git
fix(types): improve `h` overload to support union of string and component (#5432)
fix #5431
This commit is contained in:
parent
f36c49f31b
commit
16ecb44c89
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
h,
|
h,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
|
DefineComponent,
|
||||||
ref,
|
ref,
|
||||||
Fragment,
|
Fragment,
|
||||||
Teleport,
|
Teleport,
|
||||||
|
@ -231,3 +232,18 @@ describe('resolveComponent should work', () => {
|
||||||
message: '1'
|
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, {}, [])
|
||||||
|
})
|
||||||
|
|
|
@ -174,6 +174,14 @@ export function h<P>(
|
||||||
children?: RawChildren | RawSlots
|
children?: RawChildren | RawSlots
|
||||||
): VNode
|
): 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
|
// Actual implementation
|
||||||
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
|
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
|
||||||
const l = arguments.length
|
const l = arguments.length
|
||||||
|
|
Loading…
Reference in New Issue