diff --git a/xml2js/index.d.ts b/xml2js/index.d.ts index 0e180f7ba8..b23ebbbac2 100644 --- a/xml2js/index.d.ts +++ b/xml2js/index.d.ts @@ -8,8 +8,8 @@ export = xml2js; declare namespace xml2js { - function parseString(xml: string, callback: (err: any, result: any) => void): void; - function parseString(xml: string, options: OptionsV2, callback: (err: any, result: any) => void): void; + function parseString(xml: convertableToString, callback: (err: any, result: any) => void): void; + function parseString(xml: convertableToString, options: OptionsV2, callback: (err: any, result: any) => void): void; var defaults: { '0.1': Options; @@ -23,7 +23,7 @@ declare namespace xml2js { class Parser { constructor(options?: OptionsV2); - parseString(str: string, cb?: Function): void; + parseString(str: convertableToString, cb?: Function): void; } interface Options { @@ -70,5 +70,9 @@ declare namespace xml2js { chunkSize?: number; cdata?: boolean; } + + interface convertableToString { + toString(): string; + } } diff --git a/xml2js/xml2js-tests.ts b/xml2js/xml2js-tests.ts index 38306d9bb4..e0bea8cf9b 100644 --- a/xml2js/xml2js-tests.ts +++ b/xml2js/xml2js-tests.ts @@ -1,3 +1,4 @@ +/// import xml2js = require('xml2js'); @@ -67,3 +68,11 @@ var v2Defaults = xml2js.defaults['0.2']; v2Defaults.async = false; v2Defaults.chunkSize = 20000; +import fs = require('fs'); +  +fs.readFile(__dirname + '/foo.xml', function(err, data) { +    parser.parseString(data, function (err: any, result: any) { +        console.dir(result); +        console.log('Done'); +    }); +}); \ No newline at end of file