fix(types): make VNodeChildrenArrayContents type more accurate (#7287)

This commit is contained in:
katashin 2017-12-20 23:09:23 +09:00 committed by Evan You
parent e055df82fe
commit 49aae6bb15
2 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import Vue from "../index";
import Vue, { VNode } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index";
import { CreateElement } from "../vue";
@ -277,6 +277,19 @@ 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') {
const first = slot[0]
if (!Array.isArray(first) && typeof first !== 'string') {
return first;
}
}
return h();
}
})
Vue.component('functional-component', {
props: ['prop'],
functional: true,

4
types/vnode.d.ts vendored
View File

@ -3,9 +3,7 @@ import { Vue } from "./vue";
export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string;
export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string;
export interface VNodeChildrenArrayContents {
[x: number]: VNode | string | VNodeChildren;
}
export interface VNodeChildrenArrayContents extends Array<VNode | string | VNodeChildrenArrayContents> {}
export interface VNode {
tag?: string;