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:
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
Component,
|
||||
ConcreteComponent,
|
||||
Data,
|
||||
validateComponentName,
|
||||
PublicAPIComponent
|
||||
Component
|
||||
} from './component'
|
||||
import { ComponentOptions } from './componentOptions'
|
||||
import { ComponentPublicInstance } from './componentProxy'
|
||||
import { ComponentPublicInstance } from './componentPublicInstance'
|
||||
import { Directive, validateDirectiveName } from './directives'
|
||||
import { RootRenderFunction } from './renderer'
|
||||
import { InjectionKey } from './apiInject'
|
||||
@@ -21,8 +21,8 @@ export interface App<HostElement = any> {
|
||||
config: AppConfig
|
||||
use(plugin: Plugin, ...options: any[]): this
|
||||
mixin(mixin: ComponentOptions): this
|
||||
component(name: string): PublicAPIComponent | undefined
|
||||
component(name: string, component: PublicAPIComponent): this
|
||||
component(name: string): Component | undefined
|
||||
component(name: string, component: Component): this
|
||||
directive(name: string): Directive | undefined
|
||||
directive(name: string, directive: Directive): this
|
||||
mount(
|
||||
@@ -33,7 +33,7 @@ export interface App<HostElement = any> {
|
||||
provide<T>(key: InjectionKey<T> | string, value: T): this
|
||||
|
||||
// internal, but we need to expose these for the server-renderer and devtools
|
||||
_component: Component
|
||||
_component: ConcreteComponent
|
||||
_props: Data | null
|
||||
_container: HostElement | null
|
||||
_context: AppContext
|
||||
@@ -70,7 +70,7 @@ export interface AppContext {
|
||||
app: App // for devtools
|
||||
config: AppConfig
|
||||
mixins: ComponentOptions[]
|
||||
components: Record<string, PublicAPIComponent>
|
||||
components: Record<string, Component>
|
||||
directives: Record<string, Directive>
|
||||
provides: Record<string | symbol, any>
|
||||
reload?: () => void // HMR only
|
||||
@@ -104,7 +104,7 @@ export function createAppContext(): AppContext {
|
||||
}
|
||||
|
||||
export type CreateAppFunction<HostElement> = (
|
||||
rootComponent: PublicAPIComponent,
|
||||
rootComponent: Component,
|
||||
rootProps?: Data | null
|
||||
) => App<HostElement>
|
||||
|
||||
@@ -124,7 +124,7 @@ export function createAppAPI<HostElement>(
|
||||
let isMounted = false
|
||||
|
||||
const app: App = (context.app = {
|
||||
_component: rootComponent as Component,
|
||||
_component: rootComponent as ConcreteComponent,
|
||||
_props: rootProps,
|
||||
_container: null,
|
||||
_context: context,
|
||||
@@ -177,7 +177,7 @@ export function createAppAPI<HostElement>(
|
||||
return app
|
||||
},
|
||||
|
||||
component(name: string, component?: PublicAPIComponent): any {
|
||||
component(name: string, component?: Component): any {
|
||||
if (__DEV__) {
|
||||
validateComponentName(name, context.config)
|
||||
}
|
||||
@@ -208,7 +208,10 @@ export function createAppAPI<HostElement>(
|
||||
|
||||
mount(rootContainer: HostElement, isHydrate?: boolean): any {
|
||||
if (!isMounted) {
|
||||
const vnode = createVNode(rootComponent as Component, rootProps)
|
||||
const vnode = createVNode(
|
||||
rootComponent as ConcreteComponent,
|
||||
rootProps
|
||||
)
|
||||
// store app context on the root VNode.
|
||||
// this will be set on the root instance on initial mount.
|
||||
vnode.appContext = context
|
||||
|
||||
Reference in New Issue
Block a user