refactor(types): widen Component type to include consutructor types
returned from `defineComponent` ref: https://github.com/vuejs/vue-router-next/pull/421 also close #1880 Previous `Component` type is now exported as `ConcreteComponent`. This introduces a minor breaking change when calling `h(comp, { ... })` will now fail if `comp` is a of generic `Component` type, since it does not specify what props it expects.
This commit is contained in:
@@ -7,14 +7,14 @@ import {
|
||||
proxyRefs
|
||||
} from '@vue/reactivity'
|
||||
import {
|
||||
CreateComponentPublicInstance,
|
||||
ComponentPublicInstance,
|
||||
PublicInstanceProxyHandlers,
|
||||
RuntimeCompiledPublicInstanceProxyHandlers,
|
||||
createRenderContext,
|
||||
exposePropsOnRenderContext,
|
||||
exposeSetupStateOnRenderContext
|
||||
} from './componentProxy'
|
||||
exposeSetupStateOnRenderContext,
|
||||
ComponentPublicInstanceConstructor
|
||||
} from './componentPublicInstance'
|
||||
import {
|
||||
ComponentPropsOptions,
|
||||
NormalizedPropsOptions,
|
||||
@@ -110,21 +110,19 @@ export interface ClassComponent {
|
||||
__vccOpts: ComponentOptions
|
||||
}
|
||||
|
||||
export type Component = ComponentOptions | FunctionalComponent<any, any>
|
||||
/**
|
||||
* Concrete component type matches its actual value: it's either an options
|
||||
* object, or a function. Use this where the code expects to work with actual
|
||||
* values, e.g. checking if its a function or not. This is mostly for internal
|
||||
* implementation code.
|
||||
*/
|
||||
export type ConcreteComponent = ComponentOptions | FunctionalComponent<any, any>
|
||||
|
||||
// A type used in public APIs where a component type is expected.
|
||||
// The constructor type is an artificial type returned by defineComponent().
|
||||
export type PublicAPIComponent =
|
||||
| Component
|
||||
| {
|
||||
new (...args: any[]): CreateComponentPublicInstance<
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any
|
||||
>
|
||||
}
|
||||
/**
|
||||
* A type used in public APIs where a component type is expected.
|
||||
* The constructor type is an artificial type returned by defineComponent().
|
||||
*/
|
||||
export type Component = ConcreteComponent | ComponentPublicInstanceConstructor
|
||||
|
||||
export { ComponentOptions }
|
||||
|
||||
@@ -174,7 +172,7 @@ export type InternalRenderFunction = {
|
||||
*/
|
||||
export interface ComponentInternalInstance {
|
||||
uid: number
|
||||
type: Component
|
||||
type: ConcreteComponent
|
||||
parent: ComponentInternalInstance | null
|
||||
root: ComponentInternalInstance
|
||||
appContext: AppContext
|
||||
@@ -346,7 +344,7 @@ export function createComponentInstance(
|
||||
parent: ComponentInternalInstance | null,
|
||||
suspense: SuspenseBoundary | null
|
||||
) {
|
||||
const type = vnode.type as Component
|
||||
const type = vnode.type as ConcreteComponent
|
||||
// inherit parent app context - or - if root, adopt from root vnode
|
||||
const appContext =
|
||||
(parent ? parent.appContext : vnode.appContext) || emptyAppContext
|
||||
@@ -703,7 +701,7 @@ const classify = (str: string): string =>
|
||||
/* istanbul ignore next */
|
||||
export function formatComponentName(
|
||||
instance: ComponentInternalInstance | null,
|
||||
Component: Component,
|
||||
Component: ConcreteComponent,
|
||||
isRoot = false
|
||||
): string {
|
||||
let name = isFunction(Component)
|
||||
|
||||
Reference in New Issue
Block a user