(types []*Type)
| 1494 | } |
| 1495 | |
| 1496 | func (c *Checker) getCommonSupertype(types []*Type) *Type { |
| 1497 | if len(types) == 1 { |
| 1498 | return types[0] |
| 1499 | } |
| 1500 | // Remove nullable types from each of the candidates. |
| 1501 | primaryTypes := types |
| 1502 | if c.strictNullChecks { |
| 1503 | primaryTypes = core.SameMap(types, func(t *Type) *Type { |
| 1504 | return c.filterType(t, func(u *Type) bool { return u.flags&TypeFlagsNullable == 0 }) |
| 1505 | }) |
| 1506 | } |
| 1507 | // When the candidate types are all literal types with the same base type, return a union |
| 1508 | // of those literal types. Otherwise, return the leftmost type for which no type to the |
| 1509 | // right is a supertype. |
| 1510 | var supertype *Type |
| 1511 | if c.literalTypesWithSameBaseType(primaryTypes) { |
| 1512 | supertype = c.getUnionType(primaryTypes) |
| 1513 | } else { |
| 1514 | supertype = c.getSingleCommonSupertype(primaryTypes) |
| 1515 | } |
| 1516 | // Add any nullable types that occurred in the candidates back to the result. |
| 1517 | if core.Same(primaryTypes, types) { |
| 1518 | return supertype |
| 1519 | } |
| 1520 | return c.getNullableType(supertype, c.getCombinedTypeFlags(types)&TypeFlagsNullable) |
| 1521 | } |
| 1522 | |
| 1523 | func (c *Checker) getSingleCommonSupertype(types []*Type) *Type { |
| 1524 | // First, find the leftmost type for which no type to the right is a strict supertype, and if that |
no test coverage detected