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

Cannot pass domNode.children to domToReact, as the docs suggest you can (with Typescript) #1444

Open
JoshMcCullough opened this issue Jun 11, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@JoshMcCullough
Copy link

Expected Behavior

Examples in README should work correctly in terms of types / types should be correct..

Actual Behavior

The README suggests that you can directly pass domNode.children to domToReact, but you get a type error if you try to do this.

Steps to Reproduce

Try to pass a DOMNode's children to domToReact.

Reproducible Demo

N/A

Environment

N/A

Keywords

N/A

@JoshMcCullough JoshMcCullough added the bug Something isn't working label Jun 11, 2024
@remarkablemark
Copy link
Owner

@remarkablemark remarkablemark added question Further information is requested and removed bug Something isn't working labels Jun 11, 2024
@JoshMcCullough
Copy link
Author

Technically yes, I'm doing it a bit more "safely" than that:

function getChildNodes(childNodes: ChildNode[]): DOMNode[] {
  // Hacky but we need to only get named nodes (e.g. not comment nodes), and need to coerce them to be DOMNodes.
  return childNodes
    .filter(o => o instanceof Comment || o instanceof Element || o instanceof ProcessingInstruction || o instanceof Text)
    .map(o => o as DOMNode);
}

Called as:

domToReact(getChildNodes(node.children))

Coercing the type to DOMNode[] just hides the underlying type issue.

@remarkablemark
Copy link
Owner

Gotcha can you provide a reproducible example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants