mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-11 09:11:50 +00:00
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.
This commit is contained in:
parent
400a4cae37
commit
78b9ab49f1
8
src/js/globals.d.ts
vendored
8
src/js/globals.d.ts
vendored
@ -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<T extends Props> = {
|
||||
(props: T): Element;
|
||||
};
|
||||
|
||||
/**
|
||||
* A child of a JSX element.
|
||||
*/
|
||||
type Node = Element | string | boolean | null | undefined;
|
||||
type JSXNode = Node | string | boolean | null | undefined;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
function isDisplayed(node: JSX.Node): node is Exclude<JSX.Node, boolean | null | undefined> {
|
||||
function isDisplayed(node: JSX.JSXNode): node is Exclude<JSX.JSXNode, boolean | null | undefined> {
|
||||
return typeof node !== "boolean" && node != null;
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ function jsx<U extends JSX.Props>(
|
||||
}
|
||||
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<U extends JSX.Props>(
|
||||
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 };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user