type Person = {
account?: {
money: number
}
}
const person: Person = {}
// scenario 1 - No error is shown here
if (person.account?.money === 0) {
console.log("I have no money");
}
// scenario 2 - TypeScript displays 'Object is possibly 'undefined'.(2532)' error
if (person.account?.money > 0) {
console.log("I have money!!");
}
Why does TypeScript not flag an error in scenario 1, but does in scenario 2?
What is the difference between these two cases?