remarkablemark/html-react-parser

missing type for domNode.children

alex4brandung opened this issue · 4 comments

I set up the following options:

const options: HTMLReactParserOptions = {
    replace(domNode: DOMNode) {
      if ((domNode as Element).attribs && (domNode as Element).name === 'a') {
        const props = attributesToProps((domNode as Element).attribs);
        return (
          <a className={'text-heaven'} {...props}>
            {domToReact((domNode as Element).children, options)}
          </a>
        );
      }
    },
  };

I am getting the following Error in my IDE:

Bildschirmfoto 2023-12-06 um 17 18 31

I import it as es6 module...

{domToReact((domNode as Element).children as DOMNode[], options)}

fixed it! Thanks for the hint!

cini9 commented

Hey @alex4brandung thanks for the awesome lib. I'm still getting some typescript errors using domToReact in NextJS 13. My html-react-parser version is 5.1.7 and this is my code :

Screenshot 2024-02-21 at 13 54 57

Screenshot 2024-02-21 at 13 55 13

Any ideas on how to fix this ? Thanks !

EDIT February 2024 :

I found this resource to help out : https://gist.github.com/natterstefan/3bc712eca6ff88781d687b7240a78cc1

And when I imported Element from html-react-parser, it fixed the issue. Thanks again !