Skip to content

Commit 438a74a

Browse files
authoredJan 9, 2024
fix(types): fix functional component for h (#9991)
- stricter children/slots type - fix emits/`EE` type argument of `FunctionalComponent`
1 parent 2fd3905 commit 438a74a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎packages/dts-test/h.test-d.ts

+24
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import {
22
type Component,
33
type DefineComponent,
44
Fragment,
5+
type FunctionalComponent,
56
Suspense,
67
Teleport,
8+
type VNode,
79
defineComponent,
810
h,
911
ref,
@@ -77,6 +79,19 @@ describe('h inference w/ Suspense', () => {
7779
h(Suspense, { onResolve: 1 })
7880
})
7981

82+
declare const fc: FunctionalComponent<
83+
{
84+
foo: string
85+
bar?: number
86+
onClick: (evt: MouseEvent) => void
87+
},
88+
['click'],
89+
{
90+
default: () => VNode
91+
title: (scope: { id: number }) => VNode
92+
}
93+
>
94+
declare const vnode: VNode
8095
describe('h inference w/ functional component', () => {
8196
const Func = (_props: { foo: string; bar?: number }) => ''
8297
h(Func, { foo: 'hello' })
@@ -87,6 +102,15 @@ describe('h inference w/ functional component', () => {
87102
h(Func, {})
88103
// @ts-expect-error
89104
h(Func, { bar: 123 })
105+
106+
h(
107+
fc,
108+
{ foo: 'hello', onClick: () => {} },
109+
{
110+
default: () => vnode,
111+
title: ({ id }: { id: number }) => vnode,
112+
},
113+
)
90114
})
91115

92116
describe('h support w/ plain object component', () => {

‎packages/runtime-core/src/h.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from './vnode'
1111
import type { Teleport, TeleportProps } from './components/Teleport'
1212
import type { Suspense, SuspenseProps } from './components/Suspense'
13-
import { isArray, isObject } from '@vue/shared'
13+
import { type IfAny, isArray, isObject } from '@vue/shared'
1414
import type { RawSlots } from './componentSlots'
1515
import type {
1616
Component,
@@ -140,11 +140,11 @@ export function h(
140140
export function h<
141141
P,
142142
E extends EmitsOptions = {},
143-
S extends Record<string, any> = {},
143+
S extends Record<string, any> = any,
144144
>(
145-
type: FunctionalComponent<P, E, S>,
145+
type: FunctionalComponent<P, any, S, any>,
146146
props?: (RawProps & P) | ({} extends P ? null : never),
147-
children?: RawChildren | RawSlots,
147+
children?: RawChildren | IfAny<S, RawSlots, S>,
148148
): VNode
149149

150150
// catch-all for generic component types

0 commit comments

Comments
 (0)
Please sign in to comment.