From 0cb1f3806d71fc94e6c9d1511269c554b0c71863 Mon Sep 17 00:00:00 2001 From: ktsn Date: Thu, 24 Nov 2016 14:14:13 +0900 Subject: [PATCH 1/3] add types for scoped slots --- types/test/options-test.ts | 31 +++++++++++++++++++++++++++++++ types/vnode.d.ts | 5 ++++- types/vue.d.ts | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 01a34203955..68c9453edaf 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -162,6 +162,37 @@ Vue.component('component', { delimiters: ["${", "}"] } as ComponentOptions); +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 + } +} as ComponentOptions) + Vue.component('functional-component', { props: ['prop'], functional: true, diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 6bba4e535e9..097191c35fe 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,6 +1,8 @@ import { Vue } from "./vue"; -export type VNodeChildren = VNodeChildrenArrayContents | string; +export type ScopedSlot = (props: any) => VNodeChildren; + +export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string; export interface VNodeChildrenArrayContents { [x: number]: VNode | string | VNodeChildren; } @@ -34,6 +36,7 @@ export interface VNodeComponentOptions { export interface VNodeData { key?: string | number; slot?: string; + scopedSlots?: { [key: string]: ScopedSlot }; ref?: string; tag?: string; staticClass?: string; diff --git a/types/vue.d.ts b/types/vue.d.ts index 06a4fc52462..8aea4155f81 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -8,7 +8,7 @@ import { DirectiveOptions, DirectiveFunction } from "./options"; -import { VNode, VNodeData, VNodeChildren } from "./vnode"; +import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode"; import { PluginFunction, PluginObject } from "./plugin"; export type CreateElement = { @@ -40,6 +40,7 @@ export declare class Vue { readonly $children: Vue[]; readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[]}; readonly $slots: { [key: string]: VNode[] }; + readonly $scopedSlots: { [key: string]: ScopedSlot }; readonly $isServer: boolean; $mount(elementOrSelector?: Element | String, hydrating?: boolean): this; From c9c93f9798328b753012ed986dec3d9c1021b100 Mon Sep 17 00:00:00 2001 From: ktsn Date: Thu, 24 Nov 2016 14:20:30 +0900 Subject: [PATCH 2/3] update nextTick types for returning promise --- types/test/vue-test.ts | 2 ++ types/vue.d.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/test/vue-test.ts b/types/test/vue-test.ts index 77e0a24d0f6..3955a0c15bb 100644 --- a/types/test/vue-test.ts +++ b/types/test/vue-test.ts @@ -45,6 +45,7 @@ class Test extends Vue { this.$nextTick(function() { this.$nextTick; }); + this.$nextTick().then(() => {}); this.$createElement("div", {}, "message"); } @@ -71,6 +72,7 @@ class Test extends Vue { } }); this.nextTick(() => {}); + this.nextTick().then(() => {}); this.set({}, "", ""); this.set([true, false, true], 1, true); this.delete({}, ""); diff --git a/types/vue.d.ts b/types/vue.d.ts index 8aea4155f81..823828a6d5d 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -57,7 +57,8 @@ export declare class Vue { $once(event: string, callback: Function): this; $off(event?: string, callback?: Function): this; $emit(event: string, ...args: any[]): this; - $nextTick(callback?: (this: this) => void): void; + $nextTick(callback: (this: this) => void): void; + $nextTick(): Promise; $createElement: CreateElement; static config: { @@ -70,6 +71,7 @@ export declare class Vue { static extend(options: ComponentOptions | FunctionalComponentOptions): typeof Vue; static nextTick(callback: () => void, context?: any[]): void; + static nextTick(): Promise static set(object: Object, key: string, value: T): T; static set(array: T[], key: number, value: T): T; static delete(object: Object, key: string): void; From cb7a3a06730c87ce759379f0be00e5645832af9f Mon Sep 17 00:00:00 2001 From: ktsn Date: Thu, 24 Nov 2016 14:32:35 +0900 Subject: [PATCH 3/3] improve scoped slot type --- types/test/options-test.ts | 2 +- types/vnode.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 68c9453edaf..61173c8408c 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -171,7 +171,7 @@ Vue.component('component-with-scoped-slot', { return h('div', [ h('child', [ // default scoped slot as children - (props: ScopedSlotProps) => h('span', [props.msg]) + (props: ScopedSlotProps) => [h('span', [props.msg])] ]), h('child', { scopedSlots: { diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 097191c35fe..211005e288d 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,6 +1,6 @@ import { Vue } from "./vue"; -export type ScopedSlot = (props: any) => VNodeChildren; +export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string; export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string; export interface VNodeChildrenArrayContents {