fix(types): app.component should accept defineComponent return type
fix #730
This commit is contained in:
parent
9d2ac6675a
commit
57ee5df364
@ -1,4 +1,9 @@
|
|||||||
import { Component, Data, validateComponentName } from './component'
|
import {
|
||||||
|
Component,
|
||||||
|
Data,
|
||||||
|
validateComponentName,
|
||||||
|
PublicAPIComponent
|
||||||
|
} from './component'
|
||||||
import { ComponentOptions } from './apiOptions'
|
import { ComponentOptions } from './apiOptions'
|
||||||
import { ComponentPublicInstance } from './componentProxy'
|
import { ComponentPublicInstance } from './componentProxy'
|
||||||
import { Directive, validateDirectiveName } from './directives'
|
import { Directive, validateDirectiveName } from './directives'
|
||||||
@ -82,10 +87,7 @@ export function createAppContext(): AppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CreateAppFunction<HostElement> = (
|
export type CreateAppFunction<HostElement> = (
|
||||||
rootComponent:
|
rootComponent: PublicAPIComponent,
|
||||||
| Component
|
|
||||||
// for compatibility with defineComponent() return types
|
|
||||||
| { new (): ComponentPublicInstance<any, any, any, any, any> },
|
|
||||||
rootProps?: Data | null
|
rootProps?: Data | null
|
||||||
) => App<HostElement>
|
) => App<HostElement>
|
||||||
|
|
||||||
@ -156,7 +158,7 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
return app
|
return app
|
||||||
},
|
},
|
||||||
|
|
||||||
component(name: string, component?: Component): any {
|
component(name: string, component?: PublicAPIComponent): any {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
validateComponentName(name, context.config)
|
validateComponentName(name, context.config)
|
||||||
}
|
}
|
||||||
@ -166,7 +168,7 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
if (__DEV__ && context.components[name]) {
|
if (__DEV__ && context.components[name]) {
|
||||||
warn(`Component "${name}" has already been registered in target app.`)
|
warn(`Component "${name}" has already been registered in target app.`)
|
||||||
}
|
}
|
||||||
context.components[name] = component
|
context.components[name] = component as Component
|
||||||
return app
|
return app
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
ComponentInternalInstance,
|
ComponentInternalInstance,
|
||||||
Data,
|
Data,
|
||||||
Component,
|
|
||||||
SetupContext,
|
SetupContext,
|
||||||
RenderFunction,
|
RenderFunction,
|
||||||
SFCInternalOptions
|
SFCInternalOptions,
|
||||||
|
PublicAPIComponent
|
||||||
} from './component'
|
} from './component'
|
||||||
import {
|
import {
|
||||||
isFunction,
|
isFunction,
|
||||||
@ -70,10 +70,7 @@ export interface ComponentOptionsBase<
|
|||||||
push: (item: any) => void,
|
push: (item: any) => void,
|
||||||
parentInstance: ComponentInternalInstance
|
parentInstance: ComponentInternalInstance
|
||||||
) => void
|
) => void
|
||||||
components?: Record<
|
components?: Record<string, PublicAPIComponent>
|
||||||
string,
|
|
||||||
Component | { new (): ComponentPublicInstance<any, any, any, any, any> }
|
|
||||||
>
|
|
||||||
directives?: Record<string, Directive>
|
directives?: Record<string, Directive>
|
||||||
inheritAttrs?: boolean
|
inheritAttrs?: boolean
|
||||||
|
|
||||||
|
@ -53,6 +53,13 @@ export interface FunctionalComponent<P = {}> extends SFCInternalOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Component = ComponentOptions | FunctionalComponent
|
export type Component = ComponentOptions | FunctionalComponent
|
||||||
|
|
||||||
|
// 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 (): ComponentPublicInstance<any, any, any, any, any> }
|
||||||
|
|
||||||
export { ComponentOptions }
|
export { ComponentOptions }
|
||||||
|
|
||||||
type LifecycleHook = Function[] | null
|
type LifecycleHook = Function[] | null
|
||||||
|
Loading…
Reference in New Issue
Block a user