-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
TS Error: Property 'attribs' does not exist on type 'DOMNode'. #199
Comments
Thanks for opening this issue! You'll need to do an import { Element } from 'domhandler/lib/node';
const options: HTMLReactParserOptions = {
replace: (domNode) => {
if (
domNode instanceof Element &&
domNode.attribs &&
domNode.name === 'main'
) {
const props = attributesToProps(domNode.attribs);
return <div {...props} />;
}
},
}; See https://codesandbox.io/s/html-react-parser-199-ehdss Let me know if you think exporting |
Now I understand. |
If you ended up here and tried the recommended solution and it still didn't work and you aren't interested in processing "Text" nodes and only care about processing "Tag" nodes, you can try the following...
I don't know why the recommended solution did not work in our project. It looks logical. For our project |
@remarkablemark, thank you for making your great tool available! Would be great if |
@kevinpfox I'm open to exporting I'm open to a PR but I do want to make sure including this won't add to the bundle size too much. We can continue discussion in #252 if it's similar. |
Thanks for mentioning other thread. I tried the following approach and it fixed the same problem without needing to import an additional project dependency. https://gist.github.com/natterstefan/3bc712eca6ff88781d687b7240a78cc1 I'm also working on a Next.js project. |
Nice! If this is helpful, would you be interested in opening a PR to document that approach in the |
Why is this so though? I think exporting |
I tried this solution, but it does not work. The instanceof check returns false on every run. Unfortunately due to factors out of my control, we are unable to update to 1.4 (at least not yet). Do you have any other ideas? I would greatly appreciate your thoughts. Thanks! ***UPDATE: import { Element } from 'domhandler/lib/node'
//... other logic
const options: HTMLReactParserOptions = {
replace: (domNode) => {
const domElement: Element = domNode as Element;
//... logic that uses the domElement
}
} |
import { Element } from "html-react-parser"; Rather than from 'domhandler/lib/node' worked for me. |
Expected Behavior
When upgrade from version 0.14.3 to 1.0, TypeScript type errors occurs.
Actual Behavior
No error occurs.
Steps to Reproduce
Upgrade from version 0.14.3 to 1.0.
Reproducible Demo
0.14.3: https://codesandbox.io/s/mutable-surf-7r84v?file=/src/App.tsx
1.0: https://codesandbox.io/s/async-wildflower-p1wxl?file=/src/App.tsx
MEMO: 5568ed7#diff-7aa4473ede4abd9ec099e87fec67fd57afafaf39e05d493ab4533acc38547eb8
The text was updated successfully, but these errors were encountered: