1- // TypeScript Version: 3.7
1+ // TypeScript Version: 4.0
22
3- import { Element , Node , Root } from 'xast'
3+ import * as xast from 'xast'
44
5- type Children = string | Node | number | Children [ ]
5+ type Children = string | xast . Node | number | Children [ ]
66
77type Primitive = null | undefined | string | number
88
@@ -17,15 +17,15 @@ type Attributes = Record<string, Primitive>
1717 * @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF).
1818 * @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
1919 */
20- declare function xastscript ( name : string , ...children : Children [ ] ) : Element
20+ declare function xastscript ( name : string , ...children : Children [ ] ) : xast . Element
2121
2222/**
2323 * Create XML trees in xast.
2424 *
2525 * @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF).
2626 * @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
2727 */
28- declare function xastscript ( name : null , ...children : Children [ ] ) : Root
28+ declare function xastscript ( name : null , ...children : Children [ ] ) : xast . Root
2929
3030/**
3131 * Create XML trees in xast.
@@ -38,6 +38,58 @@ declare function xastscript(
3838 name : string ,
3939 attributes ?: Attributes ,
4040 ...children : Children [ ]
41- ) : Element
41+ ) : xast . Element
42+
43+ /**
44+ * This unique symbol is declared to specify the key on which JSX children are passed, without conflicting
45+ * with the Attributes type.
46+ */
47+ declare const children : unique symbol
48+
49+ /**
50+ * This namespace allows to use `xastscript` as a JSX implementation.
51+ *
52+ * This namespace is only used to support the use as JSX. It’s **not** intended for direct usage.
53+ */
54+ declare namespace xastscript . JSX {
55+ /**
56+ * This defines the return value of JSX syntax.
57+ */
58+ type Element = xast . Element | xast . Root
59+
60+ /**
61+ * This disallows the use of functional components.
62+ */
63+ type IntrinsicAttributes = never
64+
65+ /**
66+ * This defines the prop types for known elements.
67+ *
68+ * For `xastscript` this defines any string may be used in combination with `xast` `Attributes`.
69+ *
70+ * This **must** be an interface.
71+ */
72+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
73+ interface IntrinsicElements {
74+ [ tagName : string ] :
75+ | Attributes
76+ | {
77+ /**
78+ * The prop that matches `ElementChildrenAttribute` key defines the type of JSX children, defines the children type.
79+ */
80+ [ children ] ?: Children
81+ }
82+ }
83+
84+ /**
85+ * The key of this interface defines as what prop children are passed.
86+ */
87+ interface ElementChildrenAttribute {
88+ /**
89+ * Only the key matters, not the value.
90+ */
91+ [ children ] ?: never
92+ }
93+ }
4294
4395export = xastscript
0 commit comments