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: fix functional component for h #9991

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions packages/dts-test/h.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
type Component,
type DefineComponent,
Fragment,
type FunctionalComponent,
Suspense,
Teleport,
type VNode,
defineComponent,
h,
ref,
Expand Down Expand Up @@ -77,6 +79,19 @@ describe('h inference w/ Suspense', () => {
h(Suspense, { onResolve: 1 })
})

declare const fc: FunctionalComponent<
{
foo: string
bar?: number
onClick: (evt: MouseEvent) => void
},
['click'],
{
default: () => VNode
title: (scope: { id: number }) => VNode
}
>
declare const vnode: VNode
describe('h inference w/ functional component', () => {
const Func = (_props: { foo: string; bar?: number }) => ''
h(Func, { foo: 'hello' })
Expand All @@ -87,6 +102,15 @@ describe('h inference w/ functional component', () => {
h(Func, {})
// @ts-expect-error
h(Func, { bar: 123 })

h(
fc,
{ foo: 'hello', onClick: () => {} },
{
default: () => vnode,
title: ({ id }: { id: number }) => vnode,
},
)
})

describe('h support w/ plain object component', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './vnode'
import type { Teleport, TeleportProps } from './components/Teleport'
import type { Suspense, SuspenseProps } from './components/Suspense'
import { isArray, isObject } from '@vue/shared'
import { type IfAny, isArray, isObject } from '@vue/shared'
import type { RawSlots } from './componentSlots'
import type {
Component,
Expand Down Expand Up @@ -140,11 +140,11 @@ export function h(
export function h<
P,
E extends EmitsOptions = {},
S extends Record<string, any> = {},
S extends Record<string, any> = any,
>(
type: FunctionalComponent<P, E, S>,
type: FunctionalComponent<P, any, S, any>,
props?: (RawProps & P) | ({} extends P ? null : never),
children?: RawChildren | RawSlots,
children?: RawChildren | IfAny<S, RawSlots, S>,
): VNode

// catch-all for generic component types
Expand Down