I've recently created a collection of typed interfaces, each with optional fields. I'm wondering if there is an efficient method to verify that all interfaces in the array have their fields filled.
Here's the interface I'm working with:
export interface BibliographicCitation {
authors?: HTMLCollectionOf<Element>;
title: string;
date?: Element;
}
This is how I populate the array:
UPDATE
citations.forEach(citation => {
if (citation.getElementsByTagName('author').length === 0 &&
citation.getElementsByTagName('title').length === 0 &&
citation.getElementsByTagName('date').length === 0) {
const interfacedCitation: BibliographicCitation = {
title: citation.textContent.replace(/\s+/g, ' '),
};
if (!bibliographicCitations.includes(interfacedCitation)) {
bibliographicCitations.push(interfacedCitation);
}
}
else {
const interfacedCitation: BibliographicCitation = {
authors: citation.getElementsByTagName('author'),
title: String(citation.getElementsByTagName('title')[0]).replace(/\s+/g, ' '),
date: citation.getElementsByTagName('date')[0],
};
if (!bibliographicCitations.includes(interfacedCitation)) {
bibliographicCitations.push(interfacedCitation);
}
}
});
My question now is, how can I confirm that all entered interfaces have their fields filled?