Browse Source

fix(types): allow scoped slots to return a single VNode (#9563)

dev
Kael 6 years ago
committed by Evan You
parent
commit
241eea19a6
  1. 4
      types/test/options-test.ts
  2. 6
      types/vnode.d.ts
  3. 4
      types/vue.d.ts

4
types/test/options-test.ts

@ -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

6
types/vnode.d.ts

@ -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

4
types/vue.d.ts

@ -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 {
@ -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>;

Loading…
Cancel
Save