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 ComponentOptions #3651

Merged
merged 2 commits into from
Sep 13, 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: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ 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 ComponentOptions = Options.ComponentOptions;
export type ComponentOptions<V extends Vue> = Options.ComponentOptions<V>;
export type FunctionalComponentOptions = Options.FunctionalComponentOptions;
export type RenderContext = Options.RenderContext;
export type PropOptions = Options.PropOptions;
export type ComputedOptions = Options.ComputedOptions;
export type WatchHandler = Options.WatchHandler;
export type ComputedOptions<V extends Vue> = Options.ComputedOptions<V>;
export type WatchHandler<V extends Vue> = Options.WatchHandler<V>;
export type WatchOptions = Options.WatchOptions;
export type DirectiveFunction = Options.DirectiveFunction;
export type DirectiveOptions = Options.DirectiveOptions;
Expand Down
42 changes: 21 additions & 21 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ type Constructor = {

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

export interface ComponentOptions {
data?: Object | ( (this: Vue) => Object );
export interface ComponentOptions<V extends Vue> {
data?: Object | ((this: V) => Object);
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
propsData?: Object;
computed?: { [key: string]: ((this: Vue) => any) | ComputedOptions };
computed?: { [key: string]: ((this: V) => any) | ComputedOptions<V> };
methods?: { [key: string]: Function };
watch?: { [key: string]: ({ handler: WatchHandler } & WatchOptions) | WatchHandler | string };
watch?: { [key: string]: ({ handler: WatchHandler<V> } & WatchOptions) | WatchHandler<V> | string };

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

beforeCreate?(): void;
created?(): void;
beforeDestroy?(): void;
destroyed?(): void;
beforeMount?(): void;
mounted?(): void;
beforeUpdate?(): void;
updated?(): void;
beforeCreate?(this: V): void;
created?(this: V): void;
beforeDestroy?(this: V): void;
destroyed?(this: V): void;
beforeMount?(this: V): void;
mounted?(this: V): void;
beforeUpdate?(this: V): void;
updated?(this: V): void;

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

parent?: Vue;
mixins?: (ComponentOptions | typeof Vue)[];
mixins?: (ComponentOptions<Vue> | typeof Vue)[];
name?: string;
extends?: ComponentOptions | typeof Vue;
extends?: ComponentOptions<Vue> | typeof Vue;
delimiters?: [string, string];
}

Expand All @@ -63,13 +63,13 @@ export interface PropOptions {
validator?(value: any): boolean;
}

export interface ComputedOptions {
get?(this: Vue): any;
set?(this: Vue, value: any): void;
export interface ComputedOptions<V> {
get?(this: V): any;
set?(this: V, value: any): void;
cache?: boolean;
}

export type WatchHandler = <T>(val: T, oldVal: T) => void;
export type WatchHandler<V> = (this: V, val: any, oldVal: any) => void;

export interface WatchOptions {
deep?: boolean;
Expand Down
18 changes: 12 additions & 6 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface Component extends Vue {

Vue.component('component', {
data() {
this.$mount
this.a
return {
a: 1
}
Expand Down Expand Up @@ -50,7 +52,9 @@ Vue.component('component', {
},
'b': 'someMethod',
'c': {
handler(val: number, oldval: number) {},
handler(val, oldVal) {
this.a = val
},
deep: true
}
},
Expand Down Expand Up @@ -91,7 +95,9 @@ Vue.component('component', {
},
staticRenderFns: [],

beforeCreate() {},
beforeCreate() {
this.a = 1;
},
created() {},
beforeDestroy() {},
destroyed() {},
Expand Down Expand Up @@ -120,7 +126,7 @@ Vue.component('component', {
},
components: {
a: Vue.component(""),
b: {} as ComponentOptions
b: {} as ComponentOptions<Vue>
},
transitions: {},
filters: {
Expand All @@ -129,11 +135,11 @@ Vue.component('component', {
}
},
parent: new Vue,
mixins: [Vue.component(""), ({} as ComponentOptions)],
mixins: [Vue.component(""), ({} as ComponentOptions<Vue>)],
name: "Component",
extends: {} as ComponentOptions,
extends: {} as ComponentOptions<Vue>,
delimiters: ["${", "}"]
} as ComponentOptions);
} as ComponentOptions<Component>);

Vue.component('functional-component', {
props: ['prop'],
Expand Down
12 changes: 6 additions & 6 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { PluginFunction, PluginObject } from "./plugin";

export declare class Vue {

constructor(options?: ComponentOptions);
constructor(options?: ComponentOptions<Vue>);

$data: Object;
readonly $el: HTMLElement;
readonly $options: ComponentOptions;
readonly $options: ComponentOptions<this>;
readonly $parent: Vue;
readonly $root: Vue;
readonly $children: Vue[];
Expand All @@ -30,7 +30,7 @@ export declare class Vue {
$delete: typeof Vue.delete;
$watch(
expOrFn: string | Function,
callback: WatchHandler,
callback: WatchHandler<this>,
options?: WatchOptions
): (() => void);
$on(event: string, callback: Function): this;
Expand All @@ -54,7 +54,7 @@ export declare class Vue {
keyCodes: { [key: string]: number };
}

static extend(options: ComponentOptions): typeof Vue;
static extend(options: ComponentOptions<Vue>): 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 @@ -67,11 +67,11 @@ export declare class Vue {
static filter(id: string, definition?: Function): Function;
static component(
id: string,
definition?: ComponentOptions | FunctionalComponentOptions | typeof Vue
definition?: ComponentOptions<Vue> | FunctionalComponentOptions | typeof Vue
): typeof Vue;

static use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void;
static mixin(mixin: typeof Vue | ComponentOptions): void;
static mixin(mixin: typeof Vue | ComponentOptions<Vue>): void;
static compile(template: string): {
render(createElement: typeof Vue.prototype.$createElement): VNode;
staticRenderFns: (() => VNode)[];
Expand Down