This code snippet validates the 'Discharge' object by checking if it contains the correct children fields.
interface DischargeEntry {
date: string;
criteria: string;
}
const isDischargeEntry = (discharge:unknown): discharge is DischargeEntry => {
return (
(((discharge as DischargeEntry).date) !== undefined) ||
(((discharge as DischargeEntry).criteria) !== undefined)
);
}
const incorrectDischarge:unknown = {
criteria: "Thumb has healed."
};
console.log('isDischargeEntry:', isDischargeEntry(incorrectDischarge)) // = true (but should be false)
Is there a mistake in the boolean evaluation within the return statement or could the 'as' keyword be impacting the logic?