From 605ede46f71db9222d1d16f055479471ea2624fb Mon Sep 17 00:00:00 2001 From: Aaron Schiff Date: Wed, 16 May 2018 22:19:10 -0500 Subject: [PATCH] xmldoc: Corrected, expanded, and refined typings --- types/xmldoc/index.d.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/types/xmldoc/index.d.ts b/types/xmldoc/index.d.ts index d4e9f92ec6..87d3403ebb 100644 --- a/types/xmldoc/index.d.ts +++ b/types/xmldoc/index.d.ts @@ -6,31 +6,35 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped): // TypeScript Version: 2.1 export class XmlDocument extends XmlElement { - constructor(xmlString: string); + constructor(xml: string); doctype: string; } -export class XmlElement { - constructor(tag: XmlElement); +export type XmlNode = XmlElement | XmlTextNode | XmlCDataNode | XmlCommentNode; +export class XmlElement { + constructor(tag: XmlTag); + + type: 'element'; name: string; attr: XmlAttributes; val: string; - children: XmlElement[]; - firstChild: XmlElement; - lastChild: XmlElement; + children: XmlNode[]; + firstChild: XmlNode | null; + lastChild: XmlNode | null; line: number; column: number; position: number; startTagPosition: number; - eachChild(func: (child: XmlElement, index?: number, array?: XmlElement[]) => void): void; - childNamed(name: string): XmlElement; + eachChild(iterator: (child: XmlElement, index: number, array: XmlNode[]) => void): void; + eachChild(iterator: (this: T, child: XmlElement, index: number, array: XmlNode[]) => void, context: T): void; + childNamed(name: string): XmlElement | undefined; childrenNamed(name: string): XmlElement[]; - childWithAttribute(name: string, value?: string): XmlElement; - descendantWithPath(path: string): XmlElement; - valueWithPath(path: string): string; + childWithAttribute(name: string, value?: string | null): XmlElement | undefined; + descendantWithPath(path: string): XmlElement | undefined; + valueWithPath(path: string): string | undefined; toString(opts?: XmlOptions): string; toStringWithIndent(indent: string, opts?: XmlOptions): string; } @@ -38,6 +42,9 @@ export class XmlElement { export class XmlTextNode { constructor(text: string); + type: 'text'; + text: string; + toString(opts?: XmlOptions): string; toStringWithIndent(indent: string, opts?: XmlOptions): string; } @@ -45,6 +52,9 @@ export class XmlTextNode { export class XmlCDataNode { constructor(cdata: string); + type: 'cdata'; + cdata: string; + toString(opts?: XmlOptions): string; toStringWithIndent(indent: string, opts?: XmlOptions): string; } @@ -52,6 +62,9 @@ export class XmlCDataNode { export class XmlCommentNode { constructor(comment: string); + type: 'comment'; + comment: string; + toString(opts?: XmlOptions): string; toStringWithIndent(indent: string, opts?: XmlOptions): string; }