xxxxxxxxxx
objectThatMaybeBeNull?.whatYouReAccessing ?? "Default Value"
objectThatMaybeBeNull!.whatYouReAccessing
xxxxxxxxxx
If you know from external means that an expression is not null or undefined,
you can use the non-null assertion operator ! to coerce away those types:
// Error, some.expr may be null or undefined
let x = some.expr.thing;
// OK
let y = some.expr!.thing;
xxxxxxxxxx
// Error, some.expr may be null or undefined
let x = some.expr.thing;
// OK
let y = some.expr!.thing;
xxxxxxxxxx
const myObject: MyObjectType | null = possiblyNullFunction();
// Assuming you're confident myObject won't be null
myObject!.someMethod(); // Add '!' after the variable to assert non-null