Node type not exported
lazd opened this issue · 1 comments
The same way postcss-parser
exports NodeText
and NodeTag
, I would export posthtml-render
to export Node
. This would be helpful when constructing objects for use with posthtml-render
.
Details
My use case is as follows:
- Manually create an entire
Node
tree in a TypeScript project (no parsing involved) - Render the tree, return the HTML
I would expect to be able to do something like this:
import { Node, render } from 'posthtml-render';
const node: Node = {
tag: 'div',
content: [
{ tag: 'div', content: 'Hi' }
]
};
const html = render(node);
Instead, I have to do something like:
import render from 'posthtml-render';
import { NodeText, NodeTag } from 'posthtml-parser';
// re-declare the node union type manually (will be compatible since closeAs is optional)
type Node = NodeText | NodeTag;
const node: Node = {
tag: 'div',
content: [
{ tag: 'div', content: 'Hi' }
]
};
const html = render(node);
Of course, I could omit the Node
type completely and just use an implicit any
or object
, but it is a better development experience to know the type of the object I'm constructing.
I realize that posthtml-render
is mainly just a dependency of posthtml
and this use case is probably uncommon, but this would open up some additional uses of the package.
Environment
OS | node | yarn | package |
---|---|---|---|
macOS 10.15.7 | v14.17.1 | v1.22.4 | v2.0.6 |
Note: I had to work around #62 to test the above code sample (change types
to dist/index.d.ts
in node_modules/posthtml-render/package.json
).