⬅️ FEM TypeScript Fundamentals

Optional chaining ?.

  • if someObject? then .property
  • someObject?.property means: (someObject === null || someObject === undefined) ? undefined : someObject.property
type Comment = {text: string};
function getComment(): Comment | undefined {
  return undefined;
}
getComment()?.text;
 
// another example
users.map(user => user?.address?.postalCode);