Reference
idlip/jsx-runtime
idlip/jsx-runtime holds the JSX types for "jsxImportSource": "idlip". It has no runtime code: the compiler replaces every view, so a component body never runs as JSX. See Editor setup for the tsconfig.json settings.
import type { JSX } from 'idlip/jsx-runtime';
export default function Hello(props: { name: string }): JSX.Element {
return <p>Hello {props.name}</p>;
}
#Types
#JSX
namespace JSX {
type Element;
interface ElementChildrenAttribute {
children: unknown;
}
interface IntrinsicAttributes {
key?: string | number | ((item: never) => string | number);
}
interface IntrinsicElements {
/* HTML, SVG and MathML elements, <window> and <document> */
}
}
The namespace TypeScript reads for JSX. JSX.Element is what a component returns. It exists only as a type.
key also accepts a callback, which only <For> takes as its key (its own type gives the item).
IntrinsicElements types every element:
- HTML elements take the common attributes (
class,id,ref,html,key,aria-*,data-*and others), the attributes of their tag, andon:*andlatest:*props for the events of the element. - SVG and MathML elements take any attribute, plus the common ones and the event props.
htmlstaysTrustedHtml. <window>and<document>take onlyon:*andlatest:*props. They listen onwindowanddocument.- Plain
onclickstyle names are type errors, since they would set an event handler attribute. Useon:click. - A
<form>'scurrentTarget.elementshas a named field for each name an event arrow reads, such ase.currentTarget.elements.draft.value.
latest:* takes the same functions as on:* and opts into latest-wins delivery: while a message is in flight, a newer event of the same kind replaces the queued one.
#ClassValue
type ClassValue = string | Record<string, boolean | null | undefined>;
The type of class. A record adds each key whose value is true: class={{ done: t.done }}.
#EventFor
type EventFor<El extends Element, E extends Event> = E & { readonly currentTarget: El };
An event with currentTarget typed as the element the listener is on.
#EventProp
type EventProp<El extends Element, E extends Event> = (event: EventFor<El, E>) => unknown;
The type of an on:* or latest:* prop. The compiler restricts the value to a handler, or a synchronous arrow function whose statements are handler calls, if, else and const.