From 07361432b98a398b3b4eea80308efba8490fbad8 Mon Sep 17 00:00:00 2001 From: ktsn Date: Wed, 20 Dec 2017 15:44:05 +0900 Subject: [PATCH] fix(types): make VNodeChildrenArrayContents type more accurate --- types/test/options-test.ts | 15 ++++++++++++++- types/vnode.d.ts | 4 +--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/types/test/options-test.ts b/types/test/options-test.ts index e1edff3f5ad..a62d9bb259a 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -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, diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 2fd2ef13c59..5754c433dcd 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -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 {} export interface VNode { tag?: string;