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:

    1. function test(x: Bar) {
    2. x.b; // number | undefined
    3. let f1 = x.f(); // number
    4. let g1 = x.g && x.g(); // number | undefined