DefinitelyTyped/types/pixl-xml/pixl-xml-tests.ts
Evan Shortiss 1d379aed92 add pixl-xml types (#37683)
* add pixl-xml types

* address linter errors
2019-08-16 12:56:01 -07:00

24 lines
603 B
TypeScript

import * as XML from 'pixl-xml';
const xmlstring = '<xml><users id="0">Octocat</users><users id="1">Evan</users></xml>';
interface User {
id: string;
_Data: string;
}
interface UserList {
users: User[];
}
// Verify type inference from template type with constructor
const parserInstance = new XML.Parser<UserList>(xmlstring);
const usersFromParser = parserInstance.getTree().users;
usersFromParser[0].id;
// Verify type inference from template type with function
const usersFromParseFn = XML.parse(xmlstring) as UserList;
usersFromParseFn.users[0].id;
XML.stringify(usersFromParseFn);