if (type.flags & ts.TypeFlags.Union) {
        const unionType = type as ts.UnionType;

        if (unionType.types.length === 2 && unionType.types.some(t => !!(t.flags & ts.TypeFlags.Undefined))) {
            type = unionType.types.find(t => !(t.flags & ts.TypeFlags.Undefined))!;