From 46e7115e357f70bad08a11e5cc2305a95bb18b79 Mon Sep 17 00:00:00 2001 From: Kael Date: Sun, 24 Feb 2019 15:45:41 +1100 Subject: [PATCH 1/3] fix(types): allow scoped slots to return a single VNode --- types/test/options-test.ts | 4 ++++ types/vnode.d.ts | 3 ++- types/vue.d.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 166d8806108..2c67efe0665 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -323,6 +323,10 @@ Vue.component('component-with-scoped-slot', { item: (props: ScopedSlotProps) => [h('span', [props.msg])] } }), + h('child', [ + // return single VNode (will be normalized to an array) + (props: ScopedSlotProps) => h('span', [props.msg]) + ]), h('child', { // Passing down all slots from parent scopedSlots: this.$scopedSlots diff --git a/types/vnode.d.ts b/types/vnode.d.ts index d296ee2e396..772d2521bbc 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,7 +1,8 @@ import { Vue } from "./vue"; +export type ScopedSlot = (props: any) => VNode | VNode[] | string | undefined; // Scoped slots are guaranteed to return Array of VNodes starting in 2.6 -export type ScopedSlot = (props: any) => ScopedSlotChildren; +export type NormalizedScopedSlot = (props: any) => ScopedSlotChildren; export type ScopedSlotChildren = VNode[] | undefined; // Relaxed type compatible with $createElement diff --git a/types/vue.d.ts b/types/vue.d.ts index 55e44657430..156c31b7c27 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -12,7 +12,7 @@ import { ThisTypedComponentOptionsWithRecordProps, WatchOptions, } from "./options"; -import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode"; +import { VNode, VNodeData, VNodeChildren, ScopedSlot, NormalizedScopedSlot } from "./vnode"; import { PluginFunction, PluginObject } from "./plugin"; export interface CreateElement { @@ -28,7 +28,7 @@ export interface Vue { readonly $children: Vue[]; readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] }; readonly $slots: { [key: string]: VNode[] | undefined }; - readonly $scopedSlots: { [key: string]: ScopedSlot | undefined }; + readonly $scopedSlots: { [key: string]: NormalizedScopedSlot | undefined }; readonly $isServer: boolean; readonly $data: Record; readonly $props: Record; From 51c445b5ae6d0fdff803e2092f8dc32b30f8a881 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 28 Feb 2019 16:56:58 -0500 Subject: [PATCH 2/3] Update vnode.d.ts --- types/vnode.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 772d2521bbc..99b7e1abc6e 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,6 +1,9 @@ import { Vue } from "./vue"; -export type ScopedSlot = (props: any) => VNode | VNode[] | string | undefined; +export type ScopedSlot = (props: any) => ScopedSlotReturn; +type ScopedSlotReturnValue = VNode | string | boolean | null | undefined | ScopedSlotReturnArray; +interface ScopedSlotReturnArray extends Array {} + // Scoped slots are guaranteed to return Array of VNodes starting in 2.6 export type NormalizedScopedSlot = (props: any) => ScopedSlotChildren; export type ScopedSlotChildren = VNode[] | undefined; From caba8e4bff45bfe6c82588da4da8282620288c62 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 28 Feb 2019 17:00:06 -0500 Subject: [PATCH 3/3] Update vnode.d.ts --- types/vnode.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 99b7e1abc6e..62afcfeb7b9 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,6 +1,6 @@ import { Vue } from "./vue"; -export type ScopedSlot = (props: any) => ScopedSlotReturn; +export type ScopedSlot = (props: any) => ScopedSlotReturnValue; type ScopedSlotReturnValue = VNode | string | boolean | null | undefined | ScopedSlotReturnArray; interface ScopedSlotReturnArray extends Array {}