Skip to content

Commit

Permalink
fix(types): make VNodeChildrenArrayContents type more accurate (#7287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn authored and yyx990803 committed Dec 20, 2017
1 parent e055df8 commit 49aae6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 14 additions & 1 deletion types/test/options-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Vue from "../index";
import Vue, { VNode } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index";
import { CreateElement } from "../vue";

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions types/vnode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 49aae6b

Please sign in to comment.