I anticipated an error to occur in this code snippet, indicating that
b.resDetails is possibly undefined
, however, no such error occurred. Can someone please provide an explanation for this unexpected behavior? I'm quite perplexed.
type BasicDetails = {
name: string;
age: number;
resDetails?: ResidentialDetails;
};
type ResidentialDetails = {
address: string;
state: string;
city: string;
};
const b: BasicDetails = {
name: "Ronit",
age: 22,
};
console.log(b.resDetails.address);