(types, unionReduction, aliasSymbol, aliasTypeArguments, origin)
| 61283 | // circularly reference themselves and therefore cannot be subtype reduced during their declaration. |
| 61284 | // For example, "type Item = string | (() => Item" is a named type that circularly references itself. |
| 61285 | function getUnionType(types, unionReduction, aliasSymbol, aliasTypeArguments, origin) { |
| 61286 | if (unionReduction === void 0) { unionReduction = 1 /* UnionReduction.Literal */; } |
| 61287 | if (types.length === 0) { |
| 61288 | return neverType; |
| 61289 | } |
| 61290 | if (types.length === 1) { |
| 61291 | return types[0]; |
| 61292 | } |
| 61293 | var typeSet = []; |
| 61294 | var includes = addTypesToUnion(typeSet, 0, types); |
| 61295 | if (unionReduction !== 0 /* UnionReduction.None */) { |
| 61296 | if (includes & 3 /* TypeFlags.AnyOrUnknown */) { |
| 61297 | return includes & 1 /* TypeFlags.Any */ ? |
| 61298 | includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType : |
| 61299 | includes & 65536 /* TypeFlags.Null */ || containsType(typeSet, unknownType) ? unknownType : nonNullUnknownType; |
| 61300 | } |
| 61301 | if (exactOptionalPropertyTypes && includes & 32768 /* TypeFlags.Undefined */) { |
| 61302 | var missingIndex = ts.binarySearch(typeSet, missingType, getTypeId, ts.compareValues); |
| 61303 | if (missingIndex >= 0 && containsType(typeSet, undefinedType)) { |
| 61304 | ts.orderedRemoveItemAt(typeSet, missingIndex); |
| 61305 | } |
| 61306 | } |
| 61307 | if (includes & (2944 /* TypeFlags.Literal */ | 8192 /* TypeFlags.UniqueESSymbol */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 16384 /* TypeFlags.Void */ && includes & 32768 /* TypeFlags.Undefined */) { |
| 61308 | removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & 2 /* UnionReduction.Subtype */)); |
| 61309 | } |
| 61310 | if (includes & 128 /* TypeFlags.StringLiteral */ && includes & 134217728 /* TypeFlags.TemplateLiteral */) { |
| 61311 | removeStringLiteralsMatchedByTemplateLiterals(typeSet); |
| 61312 | } |
| 61313 | if (unionReduction === 2 /* UnionReduction.Subtype */) { |
| 61314 | typeSet = removeSubtypes(typeSet, !!(includes & 524288 /* TypeFlags.Object */)); |
| 61315 | if (!typeSet) { |
| 61316 | return errorType; |
| 61317 | } |
| 61318 | } |
| 61319 | if (typeSet.length === 0) { |
| 61320 | return includes & 65536 /* TypeFlags.Null */ ? includes & 4194304 /* TypeFlags.IncludesNonWideningType */ ? nullType : nullWideningType : |
| 61321 | includes & 32768 /* TypeFlags.Undefined */ ? includes & 4194304 /* TypeFlags.IncludesNonWideningType */ ? undefinedType : undefinedWideningType : |
| 61322 | neverType; |
| 61323 | } |
| 61324 | } |
| 61325 | if (!origin && includes & 1048576 /* TypeFlags.Union */) { |
| 61326 | var namedUnions = []; |
| 61327 | addNamedUnions(namedUnions, types); |
| 61328 | var reducedTypes = []; |
| 61329 | var _loop_17 = function (t) { |
| 61330 | if (!ts.some(namedUnions, function (union) { return containsType(union.types, t); })) { |
| 61331 | reducedTypes.push(t); |
| 61332 | } |
| 61333 | }; |
| 61334 | for (var _i = 0, typeSet_1 = typeSet; _i < typeSet_1.length; _i++) { |
| 61335 | var t = typeSet_1[_i]; |
| 61336 | _loop_17(t); |
| 61337 | } |
| 61338 | if (!aliasSymbol && namedUnions.length === 1 && reducedTypes.length === 0) { |
| 61339 | return namedUnions[0]; |
| 61340 | } |
| 61341 | // We create a denormalized origin type only when the union was created from one or more named unions |
| 61342 | // (unions with alias symbols or origins) and when there is no overlap between those named unions. |
no test coverage detected
searching dependent graphs…