Skip to content

Commit

Permalink
types: add EsModuleComponent definition (vuejs#6477)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored and ztlevi committed Feb 14, 2018
1 parent 9893ddc commit 97603f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions types/test/es-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
data() {
return {}
}
}
8 changes: 5 additions & 3 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)

0 comments on commit 97603f6

Please sign in to comment.