Skip to content

Commit

Permalink
fix(types): allow scoped slots to return a single VNode (vuejs#9563)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD authored and Lostlover committed Dec 10, 2019
1 parent 60c2e54 commit 65cca4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ Vue.component('component-with-scoped-slot', {
item: (props: ScopedSlotProps) => [h('span', [props.msg])]
}
}),
h('child', [
// return single VNode (will be normalized to an array)
(props: ScopedSlotProps) => h('span', [props.msg])
]),
h('child', {
// Passing down all slots from parent
scopedSlots: this.$scopedSlots
Expand Down
6 changes: 5 additions & 1 deletion types/vnode.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Vue } from "./vue";

export type ScopedSlot = (props: any) => ScopedSlotReturnValue;
type ScopedSlotReturnValue = VNode | string | boolean | null | undefined | ScopedSlotReturnArray;
interface ScopedSlotReturnArray extends Array<ScopedSlotReturnValue> {}

// Scoped slots are guaranteed to return Array of VNodes starting in 2.6
export type ScopedSlot = (props: any) => ScopedSlotChildren;
export type NormalizedScopedSlot = (props: any) => ScopedSlotChildren;
export type ScopedSlotChildren = VNode[] | undefined;

// Relaxed type compatible with $createElement
Expand Down
4 changes: 2 additions & 2 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ThisTypedComponentOptionsWithRecordProps,
WatchOptions,
} from "./options";
import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode";
import { VNode, VNodeData, VNodeChildren, ScopedSlot, NormalizedScopedSlot } from "./vnode";
import { PluginFunction, PluginObject } from "./plugin";

export interface CreateElement {
Expand All @@ -28,7 +28,7 @@ export interface Vue {
readonly $children: Vue[];
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] };
readonly $slots: { [key: string]: VNode[] | undefined };
readonly $scopedSlots: { [key: string]: ScopedSlot | undefined };
readonly $scopedSlots: { [key: string]: NormalizedScopedSlot | undefined };
readonly $isServer: boolean;
readonly $data: Record<string, any>;
readonly $props: Record<string, any>;
Expand Down

0 comments on commit 65cca4c

Please sign in to comment.