Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// TypeScript Version: 3.7

import {Attributes, Element, Node} from 'xast'
import {Element, Node} from 'xast'

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

type Primitive = null | undefined | string | number

/**
* Extending Attributes to Support JS Primitive Types
*/
type Attributes = Record<string, Primitive>

/**
* Create XML trees in xast.
Expand Down
7 changes: 7 additions & 0 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ x('urlset', {xmlns}) // $ExpectType Element
x('urlset', {xmlns}, 'string') // $ExpectType Element
x('urlset', {xmlns}, ['string', 'string']) // $ExpectType Element
x('urlset', {xmlns}, x('loc'), 'string') // $ExpectType Element
x('urlset', {xmlns}, x('loc'), 100) // $ExpectType Element
x('urlset', {xmlns}, x('loc')) // $ExpectType Element
x('urlset', {xmlns}, x('loc'), x('loc')) // $ExpectType Element
x('urlset', {xmlns}, [x('loc'), x('loc')]) // $ExpectType Element
x('urlset', {xmlns}, []) // $ExpectType Element

const xmlNumberAttribute = 100
x('urlset', {xmlNumberAttribute}, 'string') // $ExpectType Element
x('urlset', {xmlNumberAttribute}, 100) // $ExpectType Element
x('urlset', {xmlNumberAttribute}, x('loc'), 100) // $ExpectType Element
x('urlset', {xmlNumberAttribute}, []) // $ExpectType Element

x() // $ExpectError
x(false) // $ExpectError
x('urlset', x('loc'), {xmlns}) // $ExpectError