diff --git a/src/core/vdom/helpers/normalize-scoped-slots.js b/src/core/vdom/helpers/normalize-scoped-slots.js index e1772e56..d8259d0a 100644 --- a/src/core/vdom/helpers/normalize-scoped-slots.js +++ b/src/core/vdom/helpers/normalize-scoped-slots.js @@ -1,5 +1,7 @@ /* @flow */ +import { normalizeChildren } from 'core/vdom/helpers/normalize-children' + export function normalizeScopedSlots ( slots: { [key: string]: Function } | void, normalSlots: { [key: string]: Array } @@ -27,10 +29,12 @@ export function normalizeScopedSlots ( return res } -function normalizeScopedSlot(fn: Function) { +function normalizeScopedSlot(fn: Function): Function { return scope => { const res = fn(scope) - return Array.isArray(res) ? res : res ? [res] : res + return res && typeof res === 'object' + ? [res] // single vnode + : normalizeChildren(res) } } diff --git a/types/test/options-test.ts b/types/test/options-test.ts index de57e4c2..6fadd88f 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -338,8 +338,12 @@ Vue.component('component-with-scoped-slot', { components: { child: { render (this: Vue, h: CreateElement) { + const defaultSlot = this.$scopedSlots['default']!({ msg: 'hi' }) + defaultSlot && defaultSlot.forEach(vnode => { + vnode.tag + }) return h('div', [ - this.$scopedSlots['default']!({ msg: 'hi' }), + defaultSlot, this.$scopedSlots['item']!({ msg: 'hello' }) ]) } diff --git a/types/vnode.d.ts b/types/vnode.d.ts index b32f7792..11161506 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,10 +1,8 @@ import { Vue } from "./vue"; -// Scoped slots can technically return anything if used from -// a render function, but this is "good enough" for templates +// Scoped slots are guaranteed to return Array of VNodes starting in 2.6 export type ScopedSlot = (props: any) => ScopedSlotChildren; -export type ScopedSlotChildren = ScopedSlotArrayContents | VNode | string | undefined; -export interface ScopedSlotArrayContents extends Array {} +export type ScopedSlotChildren = VNode[] | undefined; // Relaxed type compatible with $createElement export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string | boolean | null | undefined;