I am attempting to turn on the strictNullChecks setting for my project, but have a rather curious error in the following snippet of code:
toasters.forEach((toster: ToasterObject) => {
if (toaster.brandName) {
//This line works just fine
let y = toaster.brandName.toLowerCase() === 'test brand name';
//This line has the error
if (!itemsArray.some(item => item.brandName.toLowerCase() === toaster.brandName.toLowerCase())) {
//do stuff
}
}
});
The error message has toaster.brandName
underlined in the if statement with the following error text: error TS2532: Object is possibly 'undefined'.
If the object is fine to use on the y = line above, why would it be a problem to use in the if statement? How can I fix this so it will quit erroring on this?