jsx.d.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Key, VNode, VNodeData } from "./vnode.js";
  2. import { ArrayOrElement } from "./h.js";
  3. import { Props } from "./modules/props.js";
  4. export type JsxVNodeChild = VNode | string | number | boolean | undefined | null;
  5. export type JsxVNodeChildren = ArrayOrElement<JsxVNodeChild>;
  6. export type FunctionComponent = (props: {
  7. [prop: string]: any;
  8. } | null, children?: VNode[]) => VNode;
  9. export declare function Fragment(data: {
  10. key?: Key;
  11. } | null, ...children: JsxVNodeChildren[]): VNode;
  12. /**
  13. * jsx/tsx compatible factory function
  14. * see: https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions
  15. */
  16. export declare function jsx(tag: string | FunctionComponent, data: VNodeData | null, ...children: JsxVNodeChildren[]): VNode;
  17. export declare namespace jsx {
  18. type Element = VNode;
  19. type IfEquals<X, Y, Output> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? Output : never;
  20. type WritableKeys<T> = {
  21. [P in keyof T]-?: IfEquals<{
  22. [Q in P]: T[P];
  23. }, {
  24. -readonly [Q in P]: T[P];
  25. }, P>;
  26. }[keyof T];
  27. type ElementProperties<T> = {
  28. [Property in WritableKeys<T> as T[Property] extends string | number | null | undefined ? Property : never]?: T[Property];
  29. };
  30. type VNodeProps<T> = ElementProperties<T> & Props;
  31. type HtmlElements = {
  32. [Property in keyof HTMLElementTagNameMap]: VNodeData<VNodeProps<HTMLElementTagNameMap[Property]>>;
  33. };
  34. interface IntrinsicElements extends HtmlElements {
  35. [elemName: string]: VNodeData;
  36. }
  37. }