Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): correct scopedSlot types #9131

Merged
merged 1 commit into from Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions 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 {
Expand Down Expand Up @@ -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
})
])
},
Expand All @@ -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();
}
})

Expand Down
4 changes: 2 additions & 2 deletions 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<VNode | string | VNodeChildrenArrayContents> {}
Expand Down Expand Up @@ -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;
Expand Down