I have this signature static cleanSOAP(envelope: [] | {}, removePassword: boolean = false) and after a constructor verification, if it's an Array I do a forEach on the envelope but, I got the error: Property 'forEach' does not exist on type '{} | []'. Property 'forEach' does not exist on type '{}'.ts(2339)
How can I prevent that ?
Code:
static cleanSOAP(envelope: [] | {}, removePassword: boolean = false) {
const unwantedProperties = ['$attributes'];
if (removePassword === true) unwantedProperties.push('password');
if (envelope && envelope.constructor === Array) {
envelope.forEach(item: => {
Helpers.cleanSOAP(item);
});
}
else if (typeof envelope === 'object') {
Object.getOwnPropertyNames(envelope)
.forEach(key => {
if (unwantedProperties.indexOf(key) !== -1) {
delete envelope[key];
}
else if (envelope[key] === null) {
delete envelope[key];
}
else if (envelope.hasOwnProperty(key) && typeof envelope[key] === 'object' && envelope[key] !== null && envelope[key].hasOwnProperty('$value')) {
envelope[key] = envelope[key]['$value'];
}
else {
Helpers.cleanSOAP(envelope[key]);
}
});
}
}
forEach?