From 4f8a6b2e536fc2cba81596af2f9e7a6351fc49aa Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 24 Apr 2020 13:30:00 -0400 Subject: [PATCH] refactor(types): remove unnecessary PublicAPIComponent type follow up for #1032 --- packages/runtime-core/src/apiAsyncComponent.ts | 16 ++++++---------- packages/runtime-core/src/apiCreateApp.ts | 17 ++++++----------- packages/runtime-core/src/apiDefineComponent.ts | 3 +++ packages/runtime-core/src/component.ts | 6 ------ packages/runtime-core/src/componentOptions.ts | 3 +-- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/packages/runtime-core/src/apiAsyncComponent.ts b/packages/runtime-core/src/apiAsyncComponent.ts index 7f65f3b47b2..a90eea02053 100644 --- a/packages/runtime-core/src/apiAsyncComponent.ts +++ b/packages/runtime-core/src/apiAsyncComponent.ts @@ -1,21 +1,17 @@ import { - PublicAPIComponent, Component, currentInstance, ComponentInternalInstance, isInSSRComponentSetup } from './component' import { isFunction, isObject } from '@vue/shared' -import { ComponentPublicInstance } from './componentProxy' import { createVNode } from './vnode' import { defineComponent } from './apiDefineComponent' import { warn } from './warning' import { ref } from '@vue/reactivity' import { handleError, ErrorCodes } from './errorHandling' -export type AsyncComponentResolveResult = - | T - | { default: T } // es modules +export type AsyncComponentResolveResult = T | { default: T } // es modules export type AsyncComponentLoader = () => Promise< AsyncComponentResolveResult @@ -23,8 +19,8 @@ export type AsyncComponentLoader = () => Promise< export interface AsyncComponentOptions { loader: AsyncComponentLoader - loadingComponent?: PublicAPIComponent - errorComponent?: PublicAPIComponent + loadingComponent?: Component + errorComponent?: Component delay?: number timeout?: number suspensible?: boolean @@ -36,9 +32,9 @@ export interface AsyncComponentOptions { ) => any } -export function defineAsyncComponent< - T extends PublicAPIComponent = { new (): ComponentPublicInstance } ->(source: AsyncComponentLoader | AsyncComponentOptions): T { +export function defineAsyncComponent( + source: AsyncComponentLoader | AsyncComponentOptions +): T { if (isFunction(source)) { source = { loader: source } } diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index c1e0538cb6d..b581bf0583d 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -1,9 +1,4 @@ -import { - Component, - Data, - validateComponentName, - PublicAPIComponent -} from './component' +import { Component, Data, validateComponentName } from './component' import { ComponentOptions } from './componentOptions' import { ComponentPublicInstance } from './componentProxy' import { Directive, validateDirectiveName } from './directives' @@ -18,8 +13,8 @@ export interface App { 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( @@ -67,7 +62,7 @@ export interface AppConfig { export interface AppContext { config: AppConfig mixins: ComponentOptions[] - components: Record + components: Record directives: Record provides: Record reload?: () => void // HMR only @@ -101,7 +96,7 @@ export function createAppContext(): AppContext { } export type CreateAppFunction = ( - rootComponent: PublicAPIComponent, + rootComponent: Component, rootProps?: Data | null ) => App @@ -172,7 +167,7 @@ export function createAppAPI( return app }, - component(name: string, component?: PublicAPIComponent): any { + component(name: string, component?: Component): any { if (__DEV__) { validateComponentName(name, context.config) } diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index c235e30c388..7ff6d0fae86 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -59,6 +59,9 @@ export function defineComponent< E, VNodeProps & Props > + // make the type compatible with `Component`. + // this can be just `typeof options` but it's not supported by API extractor + // yet } & ComponentOptionsWithoutProps // overload 3: object format with array props declaration diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index a2387a648a1..8a85392ed3c 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -73,12 +73,6 @@ export interface ClassComponent { 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 (...args: any[]): ComponentPublicInstance } - export { ComponentOptions } type LifecycleHook = Function[] | null diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 78ef9c3d735..68bf8711ee2 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -4,7 +4,6 @@ import { SetupContext, RenderFunction, SFCInternalOptions, - PublicAPIComponent, Component } from './component' import { @@ -102,7 +101,7 @@ export interface ComponentOptionsBase< push: (item: any) => void, parentInstance: ComponentInternalInstance ) => void - components?: Record + components?: Record directives?: Record inheritAttrs?: boolean emits?: E | EE[]