diff --git a/types/index.d.ts b/types/index.d.ts index 9986a75..34d047c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,6 +1,6 @@ // TypeScript Version: 3.7 -import {Element, Node} from 'xast' +import {Element, Node, Root} from 'xast' type Children = string | Node | number | Children[] @@ -19,6 +19,14 @@ type Attributes = Record */ declare function xastscript(name: string, ...children: Children[]): Element +/** + * Create XML trees in xast. + * + * @param name Qualified name. Case sensitive and can contain a namespace prefix (such as rdf:RDF). + * @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes. + */ +declare function xastscript(name: null, ...children: Children[]): Root + /** * Create XML trees in xast. * diff --git a/types/test.ts b/types/test.ts index 855264b..524b9f5 100644 --- a/types/test.ts +++ b/types/test.ts @@ -2,12 +2,17 @@ import x = require('xastscript') x('urlset') // $ExpectType Element x('urlset', 'string') // $ExpectType Element +x('urlset', 1) // $ExpectType Element x('urlset', ['string', 'string']) // $ExpectType Element x('urlset', x('loc'), 'string') // $ExpectType Element x('urlset', x('loc')) // $ExpectType Element x('urlset', x('loc'), x('loc')) // $ExpectType Element x('urlset', [x('loc'), x('loc')]) // $ExpectType Element x('urlset', []) // $ExpectType Element +x(null) // $ExpectType Root +x(null, 'string') // $ExpectType Root +x(null, 1) // $ExpectType Root +x(null, []) // $ExpectType Root const xmlns = 'http://www.sitemaps.org/schemas/sitemap/0.9' @@ -30,3 +35,4 @@ x('urlset', {xmlNumberAttribute}, []) // $ExpectType Element x() // $ExpectError x(false) // $ExpectError x('urlset', x('loc'), {xmlns}) // $ExpectError +x(null, {xmlns}) // $ExpectError