Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typings #3876

Merged
merged 2 commits into from
Oct 8, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {Vue as _Vue} from "./vue";
import * as V from "./vue";
import * as Options from "./options";
import * as Plugin from "./plugin";
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 CreateElement = V.CreateElement;

export type Component = Options.Component;
export type AsyncComponent = Options.AsyncComponent;
export type ComponentOptions<V extends Vue> = Options.ComponentOptions<V>;
Expand All @@ -30,6 +32,6 @@ declare namespace Vue {
}

// TS cannot merge imported class with namespace, declare a subclass to bypass
declare class Vue extends _Vue {}
declare class Vue extends V.Vue {}

export = Vue;
12 changes: 5 additions & 7 deletions types/options.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Vue } from "./vue";
import { Vue, CreateElement } from "./vue";
import { VNode, VNodeData, VNodeDirective } from "./vnode";

type Constructor = {
new (...args: any[]): any;
}

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

export type Component = typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions;
export type AsyncComponent = (
resolve: (component: Component) => void,
Expand All @@ -18,13 +16,13 @@ export interface ComponentOptions<V extends Vue> {
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
propsData?: Object;
computed?: { [key: string]: ((this: V) => any) | ComputedOptions<V> };
methods?: { [key: string]: Function };
methods?: { [key: string]: (this: V, ...args: any[]) => any };
watch?: { [key: string]: ({ handler: WatchHandler<V> } & WatchOptions) | WatchHandler<V> | string };

el?: Element | String;
template?: string;
render?(this: V, createElement: $createElement): VNode;
staticRenderFns?: ((createElement: $createElement) => VNode)[];
render?(this: V, createElement: CreateElement): VNode;
staticRenderFns?: ((createElement: CreateElement) => VNode)[];

beforeCreate?(this: V): void;
created?(this: V): void;
Expand All @@ -50,7 +48,7 @@ export interface ComponentOptions<V extends Vue> {
export interface FunctionalComponentOptions {
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
functional: boolean;
render(this: never, createElement: $createElement, context: RenderContext): VNode;
render(this: never, createElement: CreateElement, context: RenderContext): VNode;
name?: string;
}

Expand Down
7 changes: 4 additions & 3 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Vue.component('component', {
}
},
methods: {
plus(this: Component) {
plus() {
this.a++;
}
},
Expand Down Expand Up @@ -88,7 +88,8 @@ Vue.component('component', {
key: 'myKey',
ref: 'myRef'
}, [
createElement("div", {}, "message"),
createElement(),
createElement("div", "message"),
createElement(Vue.component("component")),
createElement({} as ComponentOptions<Vue>),
createElement({ functional: true }),
Expand All @@ -107,7 +108,7 @@ Vue.component('component', {

"message",

[createElement("div", {}, "message")]
[createElement("div", "message")]
]);
},
staticRenderFns: [],
Expand Down
24 changes: 18 additions & 6 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ import {
import { VNode, VNodeData, VNodeChildren } from "./vnode";
import { PluginFunction, PluginObject } from "./plugin";

export type CreateElement = {
// empty node
(): VNode;

// element or component name
(tag: string, children: VNodeChildren): VNode;
(tag: string, data?: VNodeData, children?: VNodeChildren): VNode;

// component constructor or options
(tag: Component, children: VNodeChildren): VNode;
(tag: Component, data?: VNodeData, children?: VNodeChildren): VNode;

// async component
(tag: AsyncComponent, children: VNodeChildren): VNode;
(tag: AsyncComponent, data?: VNodeData, children?: VNodeChildren): VNode;
}

export declare class Vue {

constructor(options?: ComponentOptions<Vue>);
Expand Down Expand Up @@ -40,12 +57,7 @@ export declare class Vue {
$off(event?: string, callback?: Function): this;
$emit(event: string, ...args: any[]): this;
$nextTick(callback?: (this: this) => void): void;
$createElement(
tag?: string | Component | AsyncComponent,
data?: VNodeData,
children?: VNodeChildren
): VNode;

$createElement: CreateElement;

static config: {
silent: boolean;
Expand Down