]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): app.component should accept defineComponent return type
authorEvan You <yyx990803@gmail.com>
Sun, 16 Feb 2020 02:04:29 +0000 (21:04 -0500)
committerEvan You <yyx990803@gmail.com>
Sun, 16 Feb 2020 02:04:29 +0000 (21:04 -0500)
fix #730

packages/runtime-core/src/apiCreateApp.ts
packages/runtime-core/src/apiOptions.ts
packages/runtime-core/src/component.ts

index e022d92f9557f0bc5cbe5fed2c3b39dbe71ea908..f8189f25e909ee5e82d036a1614c7fdac369f814 100644 (file)
@@ -1,4 +1,9 @@
-import { Component, Data, validateComponentName } from './component'
+import {
+  Component,
+  Data,
+  validateComponentName,
+  PublicAPIComponent
+} from './component'
 import { ComponentOptions } from './apiOptions'
 import { ComponentPublicInstance } from './componentProxy'
 import { Directive, validateDirectiveName } from './directives'
@@ -82,10 +87,7 @@ export function createAppContext(): AppContext {
 }
 
 export type CreateAppFunction<HostElement> = (
-  rootComponent:
-    | Component
-    // for compatibility with defineComponent() return types
-    | { new (): ComponentPublicInstance<any, any, any, any, any> },
+  rootComponent: PublicAPIComponent,
   rootProps?: Data | null
 ) => App<HostElement>
 
@@ -156,7 +158,7 @@ export function createAppAPI<HostNode, HostElement>(
         return app
       },
 
-      component(name: string, component?: Component): any {
+      component(name: string, component?: PublicAPIComponent): any {
         if (__DEV__) {
           validateComponentName(name, context.config)
         }
@@ -166,7 +168,7 @@ export function createAppAPI<HostNode, HostElement>(
         if (__DEV__ && context.components[name]) {
           warn(`Component "${name}" has already been registered in target app.`)
         }
-        context.components[name] = component
+        context.components[name] = component as Component
         return app
       },
 
index 767f5950c14c90a81f5e0178ab55441d558e94bd..3ba88f7eda94df674612ecc496450e4d4beccdce 100644 (file)
@@ -1,10 +1,10 @@
 import {
   ComponentInternalInstance,
   Data,
-  Component,
   SetupContext,
   RenderFunction,
-  SFCInternalOptions
+  SFCInternalOptions,
+  PublicAPIComponent
 } from './component'
 import {
   isFunction,
@@ -70,10 +70,7 @@ export interface ComponentOptionsBase<
     push: (item: any) => void,
     parentInstance: ComponentInternalInstance
   ) => void
-  components?: Record<
-    string,
-    Component | { new (): ComponentPublicInstance<any, any, any, any, any> }
-  >
+  components?: Record<string, PublicAPIComponent>
   directives?: Record<string, Directive>
   inheritAttrs?: boolean
 
index 538ca470ceb0cf556b7dfab5fccc9359ca8e9755..d90249a9823294e87236efa7a02a372dcb5e24cb 100644 (file)
@@ -53,6 +53,13 @@ export interface FunctionalComponent<P = {}> extends SFCInternalOptions {
 }
 
 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 }
 
 type LifecycleHook = Function[] | null