Browse Source

types: type sync for 2.6 features

dev
Evan You 6 years ago
parent
commit
0cf6aaddb5
  1. 8
      src/core/vdom/helpers/normalize-scoped-slots.js
  2. 6
      types/test/options-test.ts
  3. 6
      types/vnode.d.ts

8
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<VNode> }
@ -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)
}
}

6
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' })
])
}

6
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<ScopedSlotChildren> {}
export type ScopedSlotChildren = VNode[] | undefined;
// Relaxed type compatible with $createElement
export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string | boolean | null | undefined;

Loading…
Cancel
Save