Skip to content

types: allow (almost) anything in VNodeChildrenArrayContents #8498

Closed
@KaelWD

Description

@KaelWD

What problem does this feature solve?

The Vue runtime allows pretty much anything to be put into the children array, and simply strips away boolean | null | undefined:

if (isUndef(c) || typeof c === 'boolean') continue

The types on the other hand only allow string, VNode, or another nested array, which means we can't use short-circuit expressions to conditionally render things.

// Doesn't work - `false` is not allowed
return h('div', data, [
  this.enableSomething && h(Something)
])

// We have to do
const children: VNodeChildrenArrayContents = []
this.enableSomething && children.push(h(Something))
return h('div', data, children)

// Or
return h('div', data, [
  this.enableSomething ? h(Something) : []
])

What does the proposed API look like?

Add a separate type for createElement that also allows boolean | null | undefined, that way vnode.children can still be the current normalised version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions