(unionType)
| 69482 | // Return the name of a discriminant property for which it was possible and feasible to construct a map of |
| 69483 | // constituent types keyed by the literal types of the property by that name in each constituent type. |
| 69484 | function getKeyPropertyName(unionType) { |
| 69485 | var types = unionType.types; |
| 69486 | // We only construct maps for unions with many non-primitive constituents. |
| 69487 | if (types.length < 10 || ts.getObjectFlags(unionType) & 32768 /* ObjectFlags.PrimitiveUnion */ || |
| 69488 | ts.countWhere(types, function (t) { return !!(t.flags & (524288 /* TypeFlags.Object */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */)); }) < 10) { |
| 69489 | return undefined; |
| 69490 | } |
| 69491 | if (unionType.keyPropertyName === undefined) { |
| 69492 | // The candidate key property name is the name of the first property with a unit type in one of the |
| 69493 | // constituent types. |
| 69494 | var keyPropertyName = ts.forEach(types, function (t) { |
| 69495 | return t.flags & (524288 /* TypeFlags.Object */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */) ? |
| 69496 | ts.forEach(getPropertiesOfType(t), function (p) { return isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined; }) : |
| 69497 | undefined; |
| 69498 | }); |
| 69499 | var mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName); |
| 69500 | unionType.keyPropertyName = mapByKeyProperty ? keyPropertyName : ""; |
| 69501 | unionType.constituentMap = mapByKeyProperty; |
| 69502 | } |
| 69503 | return unionType.keyPropertyName.length ? unionType.keyPropertyName : undefined; |
| 69504 | } |
| 69505 | // Given a union type for which getKeyPropertyName returned a non-undefined result, return the constituent |
| 69506 | // that corresponds to the given key type for that property name. |
| 69507 | function getConstituentTypeForKeyType(unionType, keyType) { |
no test coverage detected
searching dependent graphs…