Skip to content

Commit 0cf6aad

Browse files
committed
types: type sync for 2.6 features
1 parent 9ae80ac commit 0cf6aad

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Diff for: src/core/vdom/helpers/normalize-scoped-slots.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* @flow */
22

3+
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
4+
35
export function normalizeScopedSlots (
46
slots: { [key: string]: Function } | void,
57
normalSlots: { [key: string]: Array<VNode> }
@@ -27,10 +29,12 @@ export function normalizeScopedSlots (
2729
return res
2830
}
2931

30-
function normalizeScopedSlot(fn: Function) {
32+
function normalizeScopedSlot(fn: Function): Function {
3133
return scope => {
3234
const res = fn(scope)
33-
return Array.isArray(res) ? res : res ? [res] : res
35+
return res && typeof res === 'object'
36+
? [res] // single vnode
37+
: normalizeChildren(res)
3438
}
3539
}
3640

Diff for: types/test/options-test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,12 @@ Vue.component('component-with-scoped-slot', {
338338
components: {
339339
child: {
340340
render (this: Vue, h: CreateElement) {
341+
const defaultSlot = this.$scopedSlots['default']!({ msg: 'hi' })
342+
defaultSlot && defaultSlot.forEach(vnode => {
343+
vnode.tag
344+
})
341345
return h('div', [
342-
this.$scopedSlots['default']!({ msg: 'hi' }),
346+
defaultSlot,
343347
this.$scopedSlots['item']!({ msg: 'hello' })
344348
])
345349
}

Diff for: types/vnode.d.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Vue } from "./vue";
22

3-
// Scoped slots can technically return anything if used from
4-
// a render function, but this is "good enough" for templates
3+
// Scoped slots are guaranteed to return Array of VNodes starting in 2.6
54
export type ScopedSlot = (props: any) => ScopedSlotChildren;
6-
export type ScopedSlotChildren = ScopedSlotArrayContents | VNode | string | undefined;
7-
export interface ScopedSlotArrayContents extends Array<ScopedSlotChildren> {}
5+
export type ScopedSlotChildren = VNode[] | undefined;
86

97
// Relaxed type compatible with $createElement
108
export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string | boolean | null | undefined;

0 commit comments

Comments
 (0)