1
- // TypeScript Version: 3.7
1
+ // TypeScript Version: 4.0
2
2
3
- import { Element , Node , Root } from 'xast'
3
+ import * as xast from 'xast'
4
4
5
- type Children = string | Node | number | Children [ ]
5
+ type Children = string | xast . Node | number | Children [ ]
6
6
7
7
type Primitive = null | undefined | string | number
8
8
@@ -17,15 +17,15 @@ type Attributes = Record<string, Primitive>
17
17
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF).
18
18
* @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
19
19
*/
20
- declare function xastscript ( name : string , ...children : Children [ ] ) : Element
20
+ declare function xastscript ( name : string , ...children : Children [ ] ) : xast . Element
21
21
22
22
/**
23
23
* Create XML trees in xast.
24
24
*
25
25
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF).
26
26
* @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
27
27
*/
28
- declare function xastscript ( name : null , ...children : Children [ ] ) : Root
28
+ declare function xastscript ( name : null , ...children : Children [ ] ) : xast . Root
29
29
30
30
/**
31
31
* Create XML trees in xast.
@@ -38,6 +38,58 @@ declare function xastscript(
38
38
name : string ,
39
39
attributes ?: Attributes ,
40
40
...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
+ }
42
94
43
95
export = xastscript
0 commit comments