Example
When compiled in mode, optional properties and methods automatically have undefined
included in their type. Thus, the b
property above is of type number | undefined
and the g
method above is of type .Type guards can be used to strip away the undefined
part of the type:
function test(x: Bar) {
x.b; // number | undefined
let f1 = x.f(); // number
let g1 = x.g && x.g(); // number | undefined