Repository: remarkablemark/html-react-parser (ts)

Issue:
TS error: domToReact(node.children) not working in v1.0.0+
## Expected Behavior

Replace using `domToReact(node.children)` as shown in README should work in Typescript.

## Actual Behavior

```
Argument of type 'Node[]' is not assignable to parameter of type 'DOMNode[]'.
  Type 'Node' is not assignable to type 'DOMNode'.
    Type 'Node' is missing the following properties from type 'Text': data, nodeValuets(2345)
```

## Reproducible Demo

https://codesandbox.io/s/little-dew-h4l9h?file=/src/App.tsx

## Environment

- Version: 1.0.0+


Pull request:
fix(index): include domhandler `Node` in `DOMNode` type
Fixes #207

## What is the motivation for this pull request?

fix(index): include domhandler `Node` in `DOMNode` type

## What is the current behavior?

```ts
import {
  Comment,
  DomHandlerOptions,
  Element,
  ProcessingInstruction,
  Text
} from 'domhandler';

export { Comment, Element, ProcessingInstruction, Text };

export type DOMNode = Comment | Element | ProcessingInstruction | Text;
```

## What is the new behavior?

```ts
import {
  Comment,
  DomHandlerOptions,
  Element,
  Node,
  ProcessingInstruction,
  Text
} from 'domhandler';

export { Comment, Element, Node, ProcessingInstruction, Text };

export type DOMNode = Comment | Element | Node | ProcessingInstruction | Text;
```

## Checklist:

- [x] Tests
- [x] Types


Patch:
diff --git a/index.d.ts b/index.d.ts
index 922003a..16bfee7 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -5,6 +5,7 @@ import {
   Comment,
   DomHandlerOptions,
   Element,
+  Node,
   ProcessingInstruction,
   Text
 } from 'domhandler';
@@ -15,8 +16,8 @@ import domToReact from './lib/dom-to-react';
 
 export { attributesToProps, domToReact, htmlToDOM };
 export type HTMLParser2Options = ParserOptions & DomHandlerOptions;
-export { Comment, Element, ProcessingInstruction, Text };
-export type DOMNode = Comment | Element | ProcessingInstruction | Text;
+export { Comment, Element, Node, ProcessingInstruction, Text };
+export type DOMNode = Comment | Element | Node | ProcessingInstruction | Text;
 
 export interface HTMLReactParserOptions {
   htmlparser2?: HTMLParser2Options;


Test patch:
diff --git a/test/types/index.tsx b/test/types/index.tsx
index 2cc5626..7679fa2 100644
--- a/test/types/index.tsx
+++ b/test/types/index.tsx
@@ -39,7 +39,9 @@ parse('<br id="remove">', {
   }
 });
 
-const options: HTMLReactParserOptions = {
+let options: HTMLReactParserOptions;
+
+options = {
   replace: domNode => {
     if (domNode instanceof Element && domNode.attribs.id === 'header') {
       return;
@@ -47,6 +49,14 @@ const options: HTMLReactParserOptions = {
   }
 };
 
+options = {
+  replace: domNode => {
+    if (domNode instanceof Element) {
+      return <>{domToReact(domNode.children)}</>;
+    }
+  }
+};
+
 // $ExpectType string | Element | Element[]
 parse('<a id="header" href="#">Heading</a>', options);
 
@@ -76,7 +86,7 @@ parse('<p/><p/>', {
 // $ExpectType string | Element | Element[]
 parse('\t<p>text \r</p>\n', { trim: true });
 
-// $ExpectType DOMNode[]
+// $ExpectType (Comment | Element | ProcessingInstruction | Text)[]
 const domNodes = htmlToDOM('<div>text</div>');
 
 // $ExpectType string | Element | Element[]
diff --git a/test/types/lib/dom-to-react.tsx b/test/types/lib/dom-to-react.tsx
index 88903dd..32e4da4 100644
--- a/test/types/lib/dom-to-react.tsx
+++ b/test/types/lib/dom-to-react.tsx
@@ -4,7 +4,7 @@ import domToReact from 'html-react-parser/lib/dom-to-react';
 import * as React from 'react';
 import htmlToDOM from 'html-dom-parser';
 
-// $ExpectType DOMNode[]
+// $ExpectType (Comment | Element | ProcessingInstruction | Text)[]
 htmlToDOM('<div>text</div>');
 
 // $ExpectType string | Element | Element[]