Skip to content

Commit

Permalink
fix(types): h support for resolveComponent (#2402)
Browse files Browse the repository at this point in the history
close #2357
  • Loading branch information
pikax authored Oct 20, 2020
1 parent fff62e2 commit 1f2a652
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 17 additions & 1 deletion packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

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

// concrete component
export function h<P>(
type: ConcreteComponent | string,
children?: RawChildren
): VNode
export function h<P>(
type: ConcreteComponent<P> | string,
props?: (RawProps & P) | ({} extends P ? null : never),
children?: RawChildren
): VNode

// component without props
export function h(
type: Component,
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/helpers/resolveAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion test-dts/h.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Suspense,
Component,
expectError,
expectAssignable
expectAssignable,
resolveComponent
} from './index'

describe('h inference w/ element', () => {
Expand Down Expand Up @@ -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'
})
})

0 comments on commit 1f2a652

Please sign in to comment.