Skip to content

Commit

Permalink
Update types for new features of v2.1 (#4305)
Browse files Browse the repository at this point in the history
* add types for scoped slots

* update nextTick types for returning promise

* improve scoped slot type
  • Loading branch information
ktsn authored and yyx990803 committed Nov 25, 2016
1 parent db3e1c7 commit fba78d4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
31 changes: 31 additions & 0 deletions types/test/options-test.ts
Expand Up @@ -162,6 +162,37 @@ Vue.component('component', {
delimiters: ["${", "}"] delimiters: ["${", "}"]
} as ComponentOptions<Component>); } as ComponentOptions<Component>);


Vue.component('component-with-scoped-slot', {
render (h) {
interface ScopedSlotProps {
msg: string
}

return h('div', [
h('child', [
// default scoped slot as children
(props: ScopedSlotProps) => [h('span', [props.msg])]
]),
h('child', {
scopedSlots: {
// named scoped slot as vnode data
item: (props: ScopedSlotProps) => [h('span', [props.msg])]
}
})
])
},
components: {
child: {
render (h) {
return h('div', [
this.$scopedSlots['default']({ msg: 'hi' }),
this.$scopedSlots['item']({ msg: 'hello' })
])
}
} as ComponentOptions<Vue>
}
} as ComponentOptions<Vue>)

Vue.component('functional-component', { Vue.component('functional-component', {
props: ['prop'], props: ['prop'],
functional: true, functional: true,
Expand Down
2 changes: 2 additions & 0 deletions types/test/vue-test.ts
Expand Up @@ -45,6 +45,7 @@ class Test extends Vue {
this.$nextTick(function() { this.$nextTick(function() {
this.$nextTick; this.$nextTick;
}); });
this.$nextTick().then(() => {});
this.$createElement("div", {}, "message"); this.$createElement("div", {}, "message");
} }


Expand All @@ -71,6 +72,7 @@ class Test extends Vue {
} }
}); });
this.nextTick(() => {}); this.nextTick(() => {});
this.nextTick().then(() => {});
this.set({}, "", ""); this.set({}, "", "");
this.set([true, false, true], 1, true); this.set([true, false, true], 1, true);
this.delete({}, ""); this.delete({}, "");
Expand Down
5 changes: 4 additions & 1 deletion types/vnode.d.ts
@@ -1,6 +1,8 @@
import { Vue } from "./vue"; import { Vue } from "./vue";


export type VNodeChildren = VNodeChildrenArrayContents | string; export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string;

export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string;
export interface VNodeChildrenArrayContents { export interface VNodeChildrenArrayContents {
[x: number]: VNode | string | VNodeChildren; [x: number]: VNode | string | VNodeChildren;
} }
Expand Down Expand Up @@ -34,6 +36,7 @@ export interface VNodeComponentOptions {
export interface VNodeData { export interface VNodeData {
key?: string | number; key?: string | number;
slot?: string; slot?: string;
scopedSlots?: { [key: string]: ScopedSlot };
ref?: string; ref?: string;
tag?: string; tag?: string;
staticClass?: string; staticClass?: string;
Expand Down
7 changes: 5 additions & 2 deletions types/vue.d.ts
Expand Up @@ -8,7 +8,7 @@ import {
DirectiveOptions, DirectiveOptions,
DirectiveFunction DirectiveFunction
} from "./options"; } from "./options";
import { VNode, VNodeData, VNodeChildren } from "./vnode"; import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode";
import { PluginFunction, PluginObject } from "./plugin"; import { PluginFunction, PluginObject } from "./plugin";


export type CreateElement = { export type CreateElement = {
Expand Down Expand Up @@ -40,6 +40,7 @@ export declare class Vue {
readonly $children: Vue[]; readonly $children: Vue[];
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[]}; readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[]};
readonly $slots: { [key: string]: VNode[] }; readonly $slots: { [key: string]: VNode[] };
readonly $scopedSlots: { [key: string]: ScopedSlot };
readonly $isServer: boolean; readonly $isServer: boolean;


$mount(elementOrSelector?: Element | String, hydrating?: boolean): this; $mount(elementOrSelector?: Element | String, hydrating?: boolean): this;
Expand All @@ -56,7 +57,8 @@ export declare class Vue {
$once(event: string, callback: Function): this; $once(event: string, callback: Function): this;
$off(event?: string, callback?: Function): this; $off(event?: string, callback?: Function): this;
$emit(event: string, ...args: any[]): this; $emit(event: string, ...args: any[]): this;
$nextTick(callback?: (this: this) => void): void; $nextTick(callback: (this: this) => void): void;
$nextTick(): Promise<void>;
$createElement: CreateElement; $createElement: CreateElement;


static config: { static config: {
Expand All @@ -69,6 +71,7 @@ export declare class Vue {


static extend(options: ComponentOptions<Vue> | FunctionalComponentOptions): typeof Vue; static extend(options: ComponentOptions<Vue> | FunctionalComponentOptions): typeof Vue;
static nextTick(callback: () => void, context?: any[]): void; static nextTick(callback: () => void, context?: any[]): void;
static nextTick(): Promise<void>
static set<T>(object: Object, key: string, value: T): T; static set<T>(object: Object, key: string, value: T): T;
static set<T>(array: T[], key: number, value: T): T; static set<T>(array: T[], key: number, value: T): T;
static delete(object: Object, key: string): void; static delete(object: Object, key: string): void;
Expand Down

0 comments on commit fba78d4

Please sign in to comment.