From ef65ec8202710eef05724e6b79d2b99e1773cc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Thu, 11 Feb 2021 11:40:06 +0100 Subject: [PATCH 01/10] Update options.d.ts --- types/options.d.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 323c7630986..243d19b8e00 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -25,13 +25,18 @@ export type AsyncComponentPromise, Methods=DefaultMethod reject: (reason?: any) => void ) => Promise | void; -export type AsyncComponentFactory, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = () => { - component: AsyncComponentPromise; +export type AsyncComponentFactory< + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + Props = DefaultProps +> = () => { + component: Promise; loading?: Component | EsModuleComponent; error?: Component | EsModuleComponent; delay?: number; timeout?: number; -} +}; /** * When the `Computed` type parameter on `ComponentOptions` is inferred, From 9b7b19329d1fe71ad202edb249344853f0263f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 12 Feb 2021 10:12:56 +0100 Subject: [PATCH 02/10] Create async-component-test.ts --- types/test/async-component-test.ts | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 types/test/async-component-test.ts diff --git a/types/test/async-component-test.ts b/types/test/async-component-test.ts new file mode 100644 index 00000000000..3e431bb01f3 --- /dev/null +++ b/types/test/async-component-test.ts @@ -0,0 +1,61 @@ +import Vue, { AsyncComponent, Component } from "../index"; + +const a: AsyncComponent = () => ({ + component: new Promise((res, rej) => { + res({ template: "" }); + }), +}); + +const b: AsyncComponent = () => ({ + // @ts-expect-error component has to be a Promise that resolves to a component + component: () => + new Promise((res, rej) => { + res({ template: "" }); + }), +}); + +const c: AsyncComponent = () => + new Promise((res, rej) => { + res({ + template: "", + }); + }); + +const d: AsyncComponent = () => + new Promise<{ default: Component }>((res, rej) => { + res({ + default: { + template: "", + }, + }); + }); + +const e: AsyncComponent = () => ({ + component: new Promise<{ default: Component }>((res, rej) => { + res({ + default: { + template: "", + }, + }); + }), +}); + +Vue.component("async-compponent1", () => ({ + component: new Promise((res, rej) => { + res({ + template: "", + }); + }), +})); + +Vue.component( + "async-compponent2", + () => + new Promise<{ default: Component }>((res, rej) => { + res({ + default: { + template: "", + }, + }); + }) +); From b0cbe18bf3e4a67cd2011f20fe12a48ea431ee47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:10:42 +0100 Subject: [PATCH 03/10] add generics to Component ad EsModuleComponent --- types/options.d.ts | 166 +++++++++++++++++++++++++++++++++------------ 1 file changed, 124 insertions(+), 42 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 243d19b8e00..46fedbfa18b 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -1,29 +1,57 @@ import { Vue, CreateElement, CombinedVueInstance } from "./vue"; -import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from "./vnode"; +import { + VNode, + VNodeData, + VNodeDirective, + NormalizedScopedSlot, +} from "./vnode"; type Constructor = { new (...args: any[]): any; -} +}; // we don't support infer props in async component // N.B. ComponentOptions is contravariant, the default generic should be bottom type -export type Component, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = +export type Component< + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + Props = DefaultProps +> = | typeof Vue | FunctionalComponentOptions - | ComponentOptions + | ComponentOptions; -interface EsModuleComponent { - default: Component +interface EsModuleComponent< + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + Props = DefaultProps +> { + default: Component; } -export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> - = AsyncComponentPromise - | AsyncComponentFactory +export type AsyncComponent< + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + Props = DefaultProps +> = + | AsyncComponentPromise + | AsyncComponentFactory; -export type AsyncComponentPromise, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = ( +export type AsyncComponentPromise< + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + Props = DefaultProps +> = ( resolve: (component: Component) => void, reject: (reason?: any) => void -) => Promise | void; +) => Promise< + | Component + | EsModuleComponent +> | void; export type AsyncComponentFactory< Data = DefaultData, @@ -31,7 +59,10 @@ export type AsyncComponentFactory< Computed = DefaultComputed, Props = DefaultProps > = () => { - component: Promise; + component: Promise< + | Component + | EsModuleComponent + >; loading?: Component | EsModuleComponent; error?: Component | EsModuleComponent; delay?: number; @@ -45,37 +76,70 @@ export type AsyncComponentFactory< * to infer from the shape of `Accessors` and work backwards. */ export type Accessors = { - [K in keyof T]: (() => T[K]) | ComputedOptions -} + [K in keyof T]: (() => T[K]) | ComputedOptions; +}; -type DataDef = Data | ((this: Readonly & V) => Data) +type DataDef = Data | ((this: Readonly & V) => Data); /** * This type should be used when an array of strings is used for a component's `props` value. */ -export type ThisTypedComponentOptionsWithArrayProps = - object & - ComponentOptions, V>, Methods, Computed, PropNames[], Record> & - ThisType>>>; +export type ThisTypedComponentOptionsWithArrayProps< + V extends Vue, + Data, + Methods, + Computed, + PropNames extends string +> = object & + ComponentOptions< + V, + DataDef, V>, + Methods, + Computed, + PropNames[], + Record + > & + ThisType< + CombinedVueInstance< + V, + Data, + Methods, + Computed, + Readonly> + > + >; /** * This type should be used when an object mapped to `PropOptions` is used for a component's `props` value. */ -export type ThisTypedComponentOptionsWithRecordProps = - object & - ComponentOptions, Methods, Computed, RecordPropsDefinition, Props> & +export type ThisTypedComponentOptionsWithRecordProps< + V extends Vue, + Data, + Methods, + Computed, + Props +> = object & + ComponentOptions< + V, + DataDef, + Methods, + Computed, + RecordPropsDefinition, + Props + > & ThisType>>; -type DefaultData = object | ((this: V) => object); +type DefaultData = object | ((this: V) => object); type DefaultProps = Record; -type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; +type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; type DefaultComputed = { [key: string]: any }; export interface ComponentOptions< V extends Vue, - Data=DefaultData, - Methods=DefaultMethods, - Computed=DefaultComputed, - PropsDef=PropsDefinition, - Props=DefaultProps> { + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + PropsDef = PropsDefinition, + Props = DefaultProps +> { data?: Data; props?: PropsDef; propsData?: object; @@ -104,7 +168,11 @@ export interface ComponentOptions< serverPrefetch?(this: V): Promise; directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; - components?: { [key: string]: Component | AsyncComponent }; + components?: { + [key: string]: + | Component + | AsyncComponent; + }; transitions?: { [key: string]: object }; filters?: { [key: string]: Function }; @@ -126,7 +194,10 @@ export interface ComponentOptions< inheritAttrs?: boolean; } -export interface FunctionalComponentOptions> { +export interface FunctionalComponentOptions< + Props = DefaultProps, + PropDefs = PropsDefinition +> { name?: string; props?: PropDefs; model?: { @@ -135,10 +206,14 @@ export interface FunctionalComponentOptions): VNode | VNode[]; + render?( + this: undefined, + createElement: CreateElement, + context: RenderContext + ): VNode | VNode[]; } -export interface RenderContext { +export interface RenderContext { props: Props; children: VNode[]; slots(): any; @@ -146,16 +221,19 @@ export interface RenderContext { parent: Vue; listeners: { [key: string]: Function | Function[] }; scopedSlots: { [key: string]: NormalizedScopedSlot }; - injections: any + injections: any; } -export type Prop = { (): T } | { new(...args: never[]): T & object } | { new(...args: string[]): Function } +export type Prop = + | { (): T } + | { new (...args: never[]): T & object } + | { new (...args: string[]): Function }; export type PropType = Prop | Prop[]; export type PropValidator = PropOptions | PropType; -export interface PropOptions { +export interface PropOptions { type?: PropType; required?: boolean; default?: T | null | undefined | (() => T | null | undefined); @@ -163,10 +241,12 @@ export interface PropOptions { } export type RecordPropsDefinition = { - [K in keyof T]: PropValidator -} + [K in keyof T]: PropValidator; +}; export type ArrayPropsDefinition = (keyof T)[]; -export type PropsDefinition = ArrayPropsDefinition | RecordPropsDefinition; +export type PropsDefinition = + | ArrayPropsDefinition + | RecordPropsDefinition; export interface ComputedOptions { get?(): T; @@ -206,6 +286,8 @@ export interface DirectiveOptions { export type InjectKey = string | symbol; -export type InjectOptions = { - [key: string]: InjectKey | { from?: InjectKey, default?: any } -} | string[]; +export type InjectOptions = + | { + [key: string]: InjectKey | { from?: InjectKey; default?: any }; + } + | string[]; From 35b689d307140acb7c66e098903e00aa695035d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:15:36 +0100 Subject: [PATCH 04/10] remove not needed , and ; --- types/test/async-component-test.ts | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/types/test/async-component-test.ts b/types/test/async-component-test.ts index 3e431bb01f3..564b200d074 100644 --- a/types/test/async-component-test.ts +++ b/types/test/async-component-test.ts @@ -2,51 +2,51 @@ import Vue, { AsyncComponent, Component } from "../index"; const a: AsyncComponent = () => ({ component: new Promise((res, rej) => { - res({ template: "" }); - }), -}); + res({ template: "" }) + }) +}) const b: AsyncComponent = () => ({ // @ts-expect-error component has to be a Promise that resolves to a component component: () => new Promise((res, rej) => { - res({ template: "" }); - }), -}); + res({ template: "" }) + }) +}) const c: AsyncComponent = () => new Promise((res, rej) => { res({ - template: "", - }); - }); + template: "" + }) + }) const d: AsyncComponent = () => new Promise<{ default: Component }>((res, rej) => { res({ default: { - template: "", - }, - }); - }); + template: "" + } + }) + }) const e: AsyncComponent = () => ({ component: new Promise<{ default: Component }>((res, rej) => { res({ default: { - template: "", - }, - }); - }), -}); + template: "" + } + }) + }) +}) Vue.component("async-compponent1", () => ({ component: new Promise((res, rej) => { res({ - template: "", - }); - }), -})); + template: "" + }) + }) +})) Vue.component( "async-compponent2", @@ -54,8 +54,8 @@ Vue.component( new Promise<{ default: Component }>((res, rej) => { res({ default: { - template: "", - }, - }); + template: "" + } + }) }) -); +) From 44313f26b021a7da791e6dfffcc811338196a377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:38:35 +0100 Subject: [PATCH 05/10] revert unrelated changes --- types/options.d.ts | 145 ++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 108 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 46fedbfa18b..779552682bf 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -1,26 +1,16 @@ import { Vue, CreateElement, CombinedVueInstance } from "./vue"; -import { - VNode, - VNodeData, - VNodeDirective, - NormalizedScopedSlot, -} from "./vnode"; +import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from "./vnode"; type Constructor = { new (...args: any[]): any; -}; +} // we don't support infer props in async component // N.B. ComponentOptions is contravariant, the default generic should be bottom type -export type Component< - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - Props = DefaultProps -> = +export type Component, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = | typeof Vue | FunctionalComponentOptions - | ComponentOptions; + | ComponentOptions interface EsModuleComponent< Data = DefaultData, @@ -31,21 +21,11 @@ interface EsModuleComponent< default: Component; } -export type AsyncComponent< - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - Props = DefaultProps -> = +export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = | AsyncComponentPromise - | AsyncComponentFactory; + | AsyncComponentFactory -export type AsyncComponentPromise< - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - Props = DefaultProps -> = ( +export type AsyncComponentPromise, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = ( resolve: (component: Component) => void, reject: (reason?: any) => void ) => Promise< @@ -76,70 +56,37 @@ export type AsyncComponentFactory< * to infer from the shape of `Accessors` and work backwards. */ export type Accessors = { - [K in keyof T]: (() => T[K]) | ComputedOptions; -}; + [K in keyof T]: (() => T[K]) | ComputedOptions +} -type DataDef = Data | ((this: Readonly & V) => Data); +type DataDef = Data | ((this: Readonly & V) => Data) /** * This type should be used when an array of strings is used for a component's `props` value. */ -export type ThisTypedComponentOptionsWithArrayProps< - V extends Vue, - Data, - Methods, - Computed, - PropNames extends string -> = object & - ComponentOptions< - V, - DataDef, V>, - Methods, - Computed, - PropNames[], - Record - > & - ThisType< - CombinedVueInstance< - V, - Data, - Methods, - Computed, - Readonly> - > - >; +export type ThisTypedComponentOptionsWithArrayProps = + object & + ComponentOptions, V>, Methods, Computed, PropNames[], Record> & + ThisType>>>; /** * This type should be used when an object mapped to `PropOptions` is used for a component's `props` value. */ -export type ThisTypedComponentOptionsWithRecordProps< - V extends Vue, - Data, - Methods, - Computed, - Props -> = object & - ComponentOptions< - V, - DataDef, - Methods, - Computed, - RecordPropsDefinition, - Props - > & +export type ThisTypedComponentOptionsWithRecordProps = + object & + ComponentOptions, Methods, Computed, RecordPropsDefinition, Props> & ThisType>>; -type DefaultData = object | ((this: V) => object); +type DefaultData = object | ((this: V) => object); type DefaultProps = Record; -type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; +type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; type DefaultComputed = { [key: string]: any }; export interface ComponentOptions< V extends Vue, - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - PropsDef = PropsDefinition, - Props = DefaultProps -> { + Data=DefaultData, + Methods=DefaultMethods, + Computed=DefaultComputed, + PropsDef=PropsDefinition, + Props=DefaultProps> { data?: Data; props?: PropsDef; propsData?: object; @@ -168,11 +115,7 @@ export interface ComponentOptions< serverPrefetch?(this: V): Promise; directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; - components?: { - [key: string]: - | Component - | AsyncComponent; - }; + components?: { [key: string]: Component | AsyncComponent }; transitions?: { [key: string]: object }; filters?: { [key: string]: Function }; @@ -194,10 +137,7 @@ export interface ComponentOptions< inheritAttrs?: boolean; } -export interface FunctionalComponentOptions< - Props = DefaultProps, - PropDefs = PropsDefinition -> { +export interface FunctionalComponentOptions> { name?: string; props?: PropDefs; model?: { @@ -206,14 +146,10 @@ export interface FunctionalComponentOptions< }; inject?: InjectOptions; functional: boolean; - render?( - this: undefined, - createElement: CreateElement, - context: RenderContext - ): VNode | VNode[]; + render?(this: undefined, createElement: CreateElement, context: RenderContext): VNode | VNode[]; } -export interface RenderContext { +export interface RenderContext { props: Props; children: VNode[]; slots(): any; @@ -221,19 +157,16 @@ export interface RenderContext { parent: Vue; listeners: { [key: string]: Function | Function[] }; scopedSlots: { [key: string]: NormalizedScopedSlot }; - injections: any; + injections: any } -export type Prop = - | { (): T } - | { new (...args: never[]): T & object } - | { new (...args: string[]): Function }; +export type Prop = { (): T } | { new(...args: never[]): T & object } | { new(...args: string[]): Function } export type PropType = Prop | Prop[]; export type PropValidator = PropOptions | PropType; -export interface PropOptions { +export interface PropOptions { type?: PropType; required?: boolean; default?: T | null | undefined | (() => T | null | undefined); @@ -241,12 +174,10 @@ export interface PropOptions { } export type RecordPropsDefinition = { - [K in keyof T]: PropValidator; -}; + [K in keyof T]: PropValidator +} export type ArrayPropsDefinition = (keyof T)[]; -export type PropsDefinition = - | ArrayPropsDefinition - | RecordPropsDefinition; +export type PropsDefinition = ArrayPropsDefinition | RecordPropsDefinition; export interface ComputedOptions { get?(): T; @@ -286,8 +217,6 @@ export interface DirectiveOptions { export type InjectKey = string | symbol; -export type InjectOptions = - | { - [key: string]: InjectKey | { from?: InjectKey; default?: any }; - } - | string[]; +export type InjectOptions = { + [key: string]: InjectKey | { from?: InjectKey, default?: any } +} | string[]; \ No newline at end of file From ee20f17fb6c1fd1fe5fbd7f715c38603dc1f402f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:46:44 +0100 Subject: [PATCH 06/10] revert unrelated changes --- types/options.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 779552682bf..45606351b97 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -7,7 +7,7 @@ type Constructor = { // we don't support infer props in async component // N.B. ComponentOptions is contravariant, the default generic should be bottom type -export type Component, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = +export type Component, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = | typeof Vue | FunctionalComponentOptions | ComponentOptions @@ -21,8 +21,8 @@ interface EsModuleComponent< default: Component; } -export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = - | AsyncComponentPromise +export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> + = AsyncComponentPromise | AsyncComponentFactory export type AsyncComponentPromise, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = ( @@ -219,4 +219,4 @@ export type InjectKey = string | symbol; export type InjectOptions = { [key: string]: InjectKey | { from?: InjectKey, default?: any } -} | string[]; \ No newline at end of file +} | string[]; From 6291ee20ba6a5978ad54861a39d6245b6af0b699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:48:39 +0100 Subject: [PATCH 07/10] revert unrelated changes --- types/options.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 45606351b97..cd7fdf60029 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -25,7 +25,7 @@ export type AsyncComponent, Methods=DefaultMethods | AsyncComponentFactory -export type AsyncComponentPromise, Methods=DefaultMethods, Computed=DefaultComputed, Props = DefaultProps> = ( +export type AsyncComponentPromise, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = ( resolve: (component: Component) => void, reject: (reason?: any) => void ) => Promise< @@ -47,7 +47,7 @@ export type AsyncComponentFactory< error?: Component | EsModuleComponent; delay?: number; timeout?: number; -}; +} /** * When the `Computed` type parameter on `ComponentOptions` is inferred, From 5250bc689cddb125860f4e5b659f6732c80de275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 15:52:34 +0100 Subject: [PATCH 08/10] revert unrelated changes --- types/options.d.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index cd7fdf60029..453c5ae2bd6 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -33,12 +33,7 @@ export type AsyncComponentPromise, Methods=DefaultMethod | EsModuleComponent > | void; -export type AsyncComponentFactory< - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - Props = DefaultProps -> = () => { +export type AsyncComponentFactory, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = () => { component: Promise< | Component | EsModuleComponent From 7e82b517896aae027a287451ed3a0208283d1467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Fri, 19 Feb 2021 20:39:59 +0100 Subject: [PATCH 09/10] optimize EsModuleImports --- types/options.d.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 453c5ae2bd6..ff266052feb 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -12,14 +12,10 @@ export type Component, Methods=DefaultMethods, Co | FunctionalComponentOptions | ComponentOptions -interface EsModuleComponent< - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - Props = DefaultProps -> { - default: Component; -} +type EsModule = T | { default: T } + +type ImportedComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> + = EsModule> export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = AsyncComponentPromise @@ -28,18 +24,12 @@ export type AsyncComponent, Methods=DefaultMethods, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = ( resolve: (component: Component) => void, reject: (reason?: any) => void -) => Promise< - | Component - | EsModuleComponent -> | void; +) => Promise> | void; export type AsyncComponentFactory, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = () => { - component: Promise< - | Component - | EsModuleComponent - >; - loading?: Component | EsModuleComponent; - error?: Component | EsModuleComponent; + component: Promise>; + loading?: ImportedComponent; + error?: ImportedComponent; delay?: number; timeout?: number; } From 271bc0f214d7d90be3621abeb7337004014ba2f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= <2pi_r2@gmx.de> Date: Thu, 25 Feb 2021 13:38:35 +0100 Subject: [PATCH 10/10] Update async-component-test.ts --- types/test/async-component-test.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/types/test/async-component-test.ts b/types/test/async-component-test.ts index 564b200d074..baa50c4b915 100644 --- a/types/test/async-component-test.ts +++ b/types/test/async-component-test.ts @@ -40,22 +40,5 @@ const e: AsyncComponent = () => ({ }) }) -Vue.component("async-compponent1", () => ({ - component: new Promise((res, rej) => { - res({ - template: "" - }) - }) -})) - -Vue.component( - "async-compponent2", - () => - new Promise<{ default: Component }>((res, rej) => { - res({ - default: { - template: "" - } - }) - }) -) +// Test that Vue.component accepts any AsyncComponent +Vue.component("async-compponent1", a)