types: add EsModuleComponent definition (#6477)

This commit is contained in:
JounQin 2017-09-05 14:25:16 -05:00 committed by Evan You
parent 08a18dd7b8
commit 0b2929a3d6
3 changed files with 16 additions and 4 deletions

7
types/options.d.ts vendored
View File

@ -6,10 +6,15 @@ type Constructor = {
}
export type Component = typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions;
interface EsModuleComponent {
default: Component
}
export type AsyncComponent = (
resolve: (component: Component) => void,
reject: (reason?: any) => void
) => Promise<Component> | Component | void;
) => Promise<Component | EsModuleComponent> | Component | void;
export interface ComponentOptions<V extends Vue> {
data?: Object | ((this: V) => Object);

5
types/test/es-module.ts Normal file
View File

@ -0,0 +1,5 @@
export default {
data() {
return {}
}
}

View File

@ -1,5 +1,5 @@
import Vue = require("../index");
import { ComponentOptions, FunctionalComponentOptions } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index";
interface Component extends Vue {
a: number;
@ -206,11 +206,13 @@ Vue.component('functional-component', {
}
} as FunctionalComponentOptions);
Vue.component("async-component", (resolve, reject) => {
Vue.component("async-component", ((resolve, reject) => {
setTimeout(() => {
resolve(Vue.component("component"));
}, 0);
return new Promise((resolve) => {
resolve({ functional: true } as FunctionalComponentOptions);
})
});
}) as AsyncComponent);
Vue.component('async-es-module-component', (() => import('./es-module')) as AsyncComponent)