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

__unsafeRenderFn (and things that depend on it) are poorly/incorrectly typed #75

Open
michaelhthomas opened this issue Oct 19, 2024 · 0 comments

Comments

@michaelhthomas
Copy link
Contributor

The type signature for __unsafeRenderFn, shown below, implies that render functions will take a set of props and numerous child Nodes as input, and will return a Node.

export function __unsafeRenderFn(
    node: ElementNode,
    fn: (props: Record<string, any>, ...children: Node[]) => Node,
)

This is completely not the case. Based on the code, all calls to node[RenderFn] pass two arguments, the attributes of the node (which will be of type Record<string, string>) and the rendered children, as an object of type { value: string }. The function is expected to return not a Node, but either a plain string, which will be treated as a text node, or a string marked with __unsafeHTML, which will be rendered without being escaped. This discrepancy in types means that the types for the swap transformer, for example, are lackluster, with lots of any types even though the types are actually known.

I would be happy to contribute a fix for these types, but wanted to make sure that the behavior here is actually what is expected before doing so.

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

No branches or pull requests

1 participant