Fix tests and use proper types for disregarding XMLComponent

This commit is contained in:
Dolan
2018-09-20 00:41:57 +01:00
parent fc71ebdfef
commit f2b50478bf
14 changed files with 68 additions and 44 deletions

View File

@ -7,10 +7,10 @@ export abstract class XmlComponent extends BaseXmlComponent {
constructor(rootKey: string) {
super(rootKey);
this.root = new Array<BaseXmlComponent>();
this.root = new Array<BaseXmlComponent | string>();
}
public prepForXml(): IXmlableObject {
public prepForXml(): IXmlableObject | undefined {
const children = this.root
.filter((c) => {
if (c instanceof BaseXmlComponent) {
@ -24,13 +24,12 @@ export abstract class XmlComponent extends BaseXmlComponent {
}
return comp;
})
.filter((comp) => comp); // Exclude null, undefined, and empty strings
.filter((comp) => comp !== undefined); // Exclude undefined
return {
[this.rootKey]: children,
};
}
// TODO: Unused method
public addChildElement(child: XmlComponent | string): XmlComponent {
this.root.push(child);