From 448ba65d2b139b29f1e6891add9925ac22ffe10b Mon Sep 17 00:00:00 2001 From: Kael Date: Tue, 4 Dec 2018 12:31:39 +1100 Subject: [PATCH] fix(types): correct scopedSlot types (#9131) see #8946 --- types/test/options-test.ts | 17 +++++++++++++---- types/vnode.d.ts | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 6c817e23..ec06f9b8 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -1,5 +1,5 @@ import Vue, { VNode } from "../index"; -import { AsyncComponent, ComponentOptions, FunctionalComponentOptions, Component } from "../index"; +import { ComponentOptions, Component } from "../index"; import { CreateElement } from "../vue"; interface MyComponent extends Vue { @@ -297,6 +297,10 @@ Vue.component('component-with-scoped-slot', { // named scoped slot as vnode data item: (props: ScopedSlotProps) => [h('span', [props.msg])] } + }), + h('child', { + // Passing down all slots from parent + scopedSlots: this.$scopedSlots }) ]) }, @@ -315,13 +319,18 @@ Vue.component('component-with-scoped-slot', { Vue.component('narrow-array-of-vnode-type', { render (h): VNode { const slot = this.$scopedSlots.default!({}) - if (typeof slot !== 'string') { + if (typeof slot === 'string') { + return h('span', slot) + } else if (Array.isArray(slot)) { const first = slot[0] if (!Array.isArray(first) && typeof first !== 'string') { - return first; + return first + } else { + return h() } + } else { + return slot } - return h(); } }) diff --git a/types/vnode.d.ts b/types/vnode.d.ts index fb18bb83..6bc41352 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,6 +1,6 @@ import { Vue } from "./vue"; -export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string; +export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | VNode | string; export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string; export interface VNodeChildrenArrayContents extends Array {} @@ -34,7 +34,7 @@ export interface VNodeComponentOptions { export interface VNodeData { key?: string | number; slot?: string; - scopedSlots?: { [key: string]: ScopedSlot }; + scopedSlots?: { [key: string]: ScopedSlot | undefined }; ref?: string; refInFor?: boolean; tag?: string;