From 78b9ab49f1c75d5e032637ed8ae053b9d6796ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Sat, 20 Jul 2024 13:35:11 +0300 Subject: [PATCH] Allow Node in JSX runtime The typings are not consistent, but they seem to work. I'll leave the rest as-is and just hope that someone fixes them later. --- src/js/globals.d.ts | 8 +++++--- src/js/jsx-runtime.ts | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/js/globals.d.ts b/src/js/globals.d.ts index 8d62ff0f..2caea804 100644 --- a/src/js/globals.d.ts +++ b/src/js/globals.d.ts @@ -158,8 +158,8 @@ declare namespace JSX { */ type IntrinsicElements = { [K in keyof HTMLElementTagNameMap]: { - children?: Node | Node[]; - [k: string]: Node | Node[] | string | number | boolean; + children?: JSXNode | JSXNode[]; + [k: string]: JSXNode | JSXNode[] | string | number | boolean; }; }; /** @@ -173,14 +173,16 @@ declare namespace JSX { * An attributes object. */ type Props = { [k: string]: unknown }; + /** * A functional component requiring attributes to match `T`. */ type Component = { (props: T): Element; }; + /** * A child of a JSX element. */ - type Node = Element | string | boolean | null | undefined; + type JSXNode = Node | string | boolean | null | undefined; } diff --git a/src/js/jsx-runtime.ts b/src/js/jsx-runtime.ts index be285029..1db25d1f 100644 --- a/src/js/jsx-runtime.ts +++ b/src/js/jsx-runtime.ts @@ -1,4 +1,4 @@ -function isDisplayed(node: JSX.Node): node is Exclude { +function isDisplayed(node: JSX.JSXNode): node is Exclude { return typeof node !== "boolean" && node != null; } @@ -27,7 +27,7 @@ function jsx( } throw new TypeError("JSX element attribute assigned invalid type"); }); - element.append(...([children].flat(Infinity) as JSX.Node[]).filter(isDisplayed)); + element.append(...([children].flat(Infinity) as JSX.JSXNode[]).filter(isDisplayed)); return element; } @@ -38,4 +38,4 @@ function jsx( const Fragment = (props: JSX.Props) => props.children as JSX.Element; // jsxs is used when there are multiple children -export { jsx, jsx as jsxs, Fragment }; +export { Fragment, jsx, jsx as jsxs };