Skip to content

Commit

Permalink
fix(types): make VNodeChildrenArrayContents type more accurate (vuejs…
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn authored and lovelope committed Feb 1, 2018
1 parent cfcea9e commit 5b25c23
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 5b25c23

Please sign in to comment.