Skip to content

Any reason why appendChild only allows Element and not NodeWithChildren? #1188

@vidhu

Description

@vidhu

Based on the function name, we should be able to append child to anything that can take children, right?

Due to the current typing

function appendChild(elem: Element, child: ChildNode): void

I get a type error with the following code

const doc = new Document([]);

const newHtmlElement = new Element('html', {}, undefined, ElementType.Tag);

appendChild(doc, newHtmlElement);

The code runs fine however typescript complains since Document is not an Element;

I think the typing is incorrect and should be

function appendChild(elem: NodeWithChildren, child: ChildNode): void

but correct me if I'm misunderstanding

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions