Skip to content

Commit 5311151

Browse files
Add support for null for root types
Closes GH-6. Reviewed-by: Titus Wormer <[email protected]>
1 parent 63c075b commit 5311151

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

types/index.d.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TypeScript Version: 3.7
22

3-
import {Element, Node} from 'xast'
3+
import {Element, Node, Root} from 'xast'
44

55
type Children = string | Node | number | Children[]
66

@@ -19,6 +19,14 @@ type Attributes = Record<string, Primitive>
1919
*/
2020
declare function xastscript(name: string, ...children: Children[]): Element
2121

22+
/**
23+
* Create XML trees in xast.
24+
*
25+
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF).
26+
* @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
27+
*/
28+
declare function xastscript(name: null, ...children: Children[]): Root
29+
2230
/**
2331
* Create XML trees in xast.
2432
*

types/test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import x = require('xastscript')
22

33
x('urlset') // $ExpectType Element
44
x('urlset', 'string') // $ExpectType Element
5+
x('urlset', 1) // $ExpectType Element
56
x('urlset', ['string', 'string']) // $ExpectType Element
67
x('urlset', x('loc'), 'string') // $ExpectType Element
78
x('urlset', x('loc')) // $ExpectType Element
89
x('urlset', x('loc'), x('loc')) // $ExpectType Element
910
x('urlset', [x('loc'), x('loc')]) // $ExpectType Element
1011
x('urlset', []) // $ExpectType Element
12+
x(null) // $ExpectType Root
13+
x(null, 'string') // $ExpectType Root
14+
x(null, 1) // $ExpectType Root
15+
x(null, []) // $ExpectType Root
1116

1217
const xmlns = 'http://www.sitemaps.org/schemas/sitemap/0.9'
1318

@@ -30,3 +35,4 @@ x('urlset', {xmlNumberAttribute}, []) // $ExpectType Element
3035
x() // $ExpectError
3136
x(false) // $ExpectError
3237
x('urlset', x('loc'), {xmlns}) // $ExpectError
38+
x(null, {xmlns}) // $ExpectError

0 commit comments

Comments
 (0)