Skip to content

Added Support for number type in Attributes #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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