Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as VNode from "./vnode";
// `Vue` in `export = Vue` must be a namespace
// All available types are exported via this namespace
declare namespace Vue {
export type Component = Options.Component;
export type AsyncComponent = Options.AsyncComponent;
export type ComponentOptions<V extends Vue> = Options.ComponentOptions<V>;
export type FunctionalComponentOptions = Options.FunctionalComponentOptions;
export type RenderContext = Options.RenderContext;
Expand Down
8 changes: 7 additions & 1 deletion types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ type Constructor = {

type $createElement = typeof Vue.prototype.$createElement;

export type Component = typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions;
export type AsyncComponent = (
resolve: (component: Component) => void,
reject: (reason?: any) => void
) => Promise<Component> | Component | void;

export interface ComponentOptions<V extends Vue> {
data?: Object | ((this: V) => Object);
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
Expand All @@ -30,7 +36,7 @@ export interface ComponentOptions<V extends Vue> {
updated?(this: V): void;

directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
components?: { [key: string]: ComponentOptions<Vue> | FunctionalComponentOptions | typeof Vue };
components?: { [key: string]: Component | AsyncComponent };
transitions?: { [key: string]: Object };
filters?: { [key: string]: Function };

Expand Down
26 changes: 26 additions & 0 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,24 @@ Vue.component('component', {
ref: 'myRef'
}, [
createElement("div", {}, "message"),
createElement(Vue.component("component")),
createElement({} as ComponentOptions<Vue>),
createElement({ functional: true }),

createElement(() => Vue.component("component")),
createElement(() => ( {} as ComponentOptions<Vue> )),
createElement(() => {
return new Promise((resolve) => {
resolve({} as ComponentOptions<Vue>);
})
}),
createElement((resolve, reject) => {
resolve({} as ComponentOptions<Vue>);
reject();
}),

"message",

[createElement("div", {}, "message")]
]);
},
Expand Down Expand Up @@ -154,3 +171,12 @@ Vue.component('functional-component', {
return createElement("div", {}, context.children);
}
} as FunctionalComponentOptions);

Vue.component("async-component", (resolve, reject) => {
setTimeout(() => {
resolve(Vue.component("component"));
}, 0);
return new Promise((resolve) => {
resolve({ functional: true } as FunctionalComponentOptions);
})
});
6 changes: 6 additions & 0 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"es5",
"dom",
"es2015.promise",
"es2015.core"
],
"module": "commonjs",
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
3 changes: 2 additions & 1 deletion types/test/vue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Test extends Vue {
this.$nextTick(function() {
this.$nextTick;
});
this.$createElement("div", {}, "message", "");
this.$createElement("div", {}, "message");
}

static testConfig() {
Expand Down Expand Up @@ -77,6 +77,7 @@ class Test extends Vue {
this.directive("", {bind() {}});
this.filter("", (value: number) => value);
this.component("", { data: () => ({}) });
this.component("", { functional: true });
this.use;
this.mixin(Test);
this.compile("<div>{{ message }}</div>");
Expand Down
14 changes: 6 additions & 8 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
Component,
AsyncComponent,
ComponentOptions,
FunctionalComponentOptions,
WatchOptions,
Expand Down Expand Up @@ -39,10 +41,9 @@ export declare class Vue {
$emit(event: string, ...args: any[]): this;
$nextTick(callback?: (this: this) => void): void;
$createElement(
tag?: string | Vue,
tag?: string | Component | AsyncComponent,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what was breaking things up for me 👍

data?: VNodeData,
children?: VNodeChildren,
namespace?: string
children?: VNodeChildren
): VNode;


Expand All @@ -54,7 +55,7 @@ export declare class Vue {
keyCodes: { [key: string]: number };
}

static extend(options: ComponentOptions<Vue>): typeof Vue;
static extend(options: ComponentOptions<Vue> | FunctionalComponentOptions): typeof Vue;
static nextTick(callback: () => void, context?: any[]): void;
static set<T>(object: Object, key: string, value: T): T;
static set<T>(array: T[], key: number, value: T): T;
Expand All @@ -65,10 +66,7 @@ export declare class Vue {
definition?: DirectiveOptions | DirectiveFunction
): DirectiveOptions;
static filter(id: string, definition?: Function): Function;
static component(
id: string,
definition?: ComponentOptions<Vue> | FunctionalComponentOptions | typeof Vue
): typeof Vue;
static component(id: string, definition?: Component | AsyncComponent): typeof Vue;

static use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void;
static mixin(mixin: typeof Vue | ComponentOptions<Vue>): void;
Expand Down