Skip to content

Commit 1f2a652

Browse files
authored
fix(types): h support for resolveComponent (#2402)
close #2357
1 parent fff62e2 commit 1f2a652

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

packages/runtime-core/src/h.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { Teleport, TeleportProps } from './components/Teleport'
1010
import { Suspense, SuspenseProps } from './components/Suspense'
1111
import { isObject, isArray } from '@vue/shared'
1212
import { RawSlots } from './componentSlots'
13-
import { FunctionalComponent, Component, ComponentOptions } from './component'
13+
import {
14+
FunctionalComponent,
15+
Component,
16+
ComponentOptions,
17+
ConcreteComponent
18+
} from './component'
1419
import { EmitsOptions } from './componentEmits'
1520
import { DefineComponent } from './apiDefineComponent'
1621

@@ -112,6 +117,17 @@ export function h<P, E extends EmitsOptions = {}>(
112117
// catch-all for generic component types
113118
export function h(type: Component, children?: RawChildren): VNode
114119

120+
// concrete component
121+
export function h<P>(
122+
type: ConcreteComponent | string,
123+
children?: RawChildren
124+
): VNode
125+
export function h<P>(
126+
type: ConcreteComponent<P> | string,
127+
props?: (RawProps & P) | ({} extends P ? null : never),
128+
children?: RawChildren
129+
): VNode
130+
115131
// component without props
116132
export function h(
117133
type: Component,

packages/runtime-core/src/helpers/resolveAssets.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const DIRECTIVES = 'directives'
1616
/**
1717
* @private
1818
*/
19-
export function resolveComponent(
20-
name: string
21-
): ConcreteComponent | string | undefined {
19+
export function resolveComponent(name: string): ConcreteComponent | string {
2220
return resolveAsset(COMPONENTS, name) || name
2321
}
2422

test-dts/h.test-d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Suspense,
99
Component,
1010
expectError,
11-
expectAssignable
11+
expectAssignable,
12+
resolveComponent
1213
} from './index'
1314

1415
describe('h inference w/ element', () => {
@@ -224,3 +225,11 @@ describe('Boolean prop implicit false', () => {
224225
// @ts-expect-error
225226
expectError(h(RequiredComponent, {}))
226227
})
228+
229+
// #2357
230+
describe('resolveComponent should work', () => {
231+
h(resolveComponent('test'))
232+
h(resolveComponent('test'), {
233+
message: '1'
234+
})
235+
})

0 commit comments

Comments
 (0)