diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index bf03247f2cb..cb87cf6ee3c 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -10,7 +10,12 @@ import { Teleport, TeleportProps } from './components/Teleport' import { Suspense, SuspenseProps } from './components/Suspense' import { isObject, isArray } from '@vue/shared' import { RawSlots } from './componentSlots' -import { FunctionalComponent, Component, ComponentOptions } from './component' +import { + FunctionalComponent, + Component, + ComponentOptions, + ConcreteComponent +} from './component' import { EmitsOptions } from './componentEmits' import { DefineComponent } from './apiDefineComponent' @@ -112,6 +117,17 @@ export function h
( // catch-all for generic component types export function h(type: Component, children?: RawChildren): VNode +// concrete component +export function h
( + type: ConcreteComponent | string, + children?: RawChildren +): VNode +export function h
( + type: ConcreteComponent
| string, + props?: (RawProps & P) | ({} extends P ? null : never), + children?: RawChildren +): VNode + // component without props export function h( type: Component, diff --git a/packages/runtime-core/src/helpers/resolveAssets.ts b/packages/runtime-core/src/helpers/resolveAssets.ts index 59c9f4cc14c..2ed49fba085 100644 --- a/packages/runtime-core/src/helpers/resolveAssets.ts +++ b/packages/runtime-core/src/helpers/resolveAssets.ts @@ -16,9 +16,7 @@ const DIRECTIVES = 'directives' /** * @private */ -export function resolveComponent( - name: string -): ConcreteComponent | string | undefined { +export function resolveComponent(name: string): ConcreteComponent | string { return resolveAsset(COMPONENTS, name) || name } diff --git a/test-dts/h.test-d.ts b/test-dts/h.test-d.ts index 877c62860cd..c71b54a2aa8 100644 --- a/test-dts/h.test-d.ts +++ b/test-dts/h.test-d.ts @@ -8,7 +8,8 @@ import { Suspense, Component, expectError, - expectAssignable + expectAssignable, + resolveComponent } from './index' describe('h inference w/ element', () => { @@ -224,3 +225,11 @@ describe('Boolean prop implicit false', () => { // @ts-expect-error expectError(h(RequiredComponent, {})) }) + +// #2357 +describe('resolveComponent should work', () => { + h(resolveComponent('test')) + h(resolveComponent('test'), { + message: '1' + }) +})