Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

@HerringtonDarkholme HerringtonDarkholme Dec 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder where is [ScopedSlot] used. VNodeChildren is used in createElement function. But it seems scopedSlots should be defined in another argument rather than VNodeChildren. https://vuejs.org/v2/guide/render-function.html#createElement-Arguments

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export interface VNodeChildrenArrayContents {
[x: number]: VNode | string | VNodeChildren;
}
export interface VNodeChildrenArrayContents extends Array<VNode | string | VNodeChildrenArrayContents> {}

export interface VNode {
tag?: string;
Expand Down