(source, target)
| 68466 | var expandingFlags = 0 /* ExpandingFlags.None */; |
| 68467 | inferFromTypes(originalSource, originalTarget); |
| 68468 | function inferFromTypes(source, target) { |
| 68469 | if (!couldContainTypeVariables(target)) { |
| 68470 | return; |
| 68471 | } |
| 68472 | if (source === wildcardType) { |
| 68473 | // We are inferring from an 'any' type. We want to infer this type for every type parameter |
| 68474 | // referenced in the target type, so we record it as the propagation type and infer from the |
| 68475 | // target to itself. Then, as we find candidates we substitute the propagation type. |
| 68476 | var savePropagationType = propagationType; |
| 68477 | propagationType = source; |
| 68478 | inferFromTypes(target, target); |
| 68479 | propagationType = savePropagationType; |
| 68480 | return; |
| 68481 | } |
| 68482 | if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) { |
| 68483 | // Source and target are types originating in the same generic type alias declaration. |
| 68484 | // Simply infer from source type arguments to target type arguments. |
| 68485 | inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments, getAliasVariances(source.aliasSymbol)); |
| 68486 | return; |
| 68487 | } |
| 68488 | if (source === target && source.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { |
| 68489 | // When source and target are the same union or intersection type, just relate each constituent |
| 68490 | // type to itself. |
| 68491 | for (var _i = 0, _a = source.types; _i < _a.length; _i++) { |
| 68492 | var t = _a[_i]; |
| 68493 | inferFromTypes(t, t); |
| 68494 | } |
| 68495 | return; |
| 68496 | } |
| 68497 | if (target.flags & 1048576 /* TypeFlags.Union */) { |
| 68498 | // First, infer between identically matching source and target constituents and remove the |
| 68499 | // matching types. |
| 68500 | var _b = inferFromMatchingTypes(source.flags & 1048576 /* TypeFlags.Union */ ? source.types : [source], target.types, isTypeOrBaseIdenticalTo), tempSources = _b[0], tempTargets = _b[1]; |
| 68501 | // Next, infer between closely matching source and target constituents and remove |
| 68502 | // the matching types. Types closely match when they are instantiations of the same |
| 68503 | // object type or instantiations of the same type alias. |
| 68504 | var _c = inferFromMatchingTypes(tempSources, tempTargets, isTypeCloselyMatchedBy), sources = _c[0], targets = _c[1]; |
| 68505 | if (targets.length === 0) { |
| 68506 | return; |
| 68507 | } |
| 68508 | target = getUnionType(targets); |
| 68509 | if (sources.length === 0) { |
| 68510 | // All source constituents have been matched and there is nothing further to infer from. |
| 68511 | // However, simply making no inferences is undesirable because it could ultimately mean |
| 68512 | // inferring a type parameter constraint. Instead, make a lower priority inference from |
| 68513 | // the full source to whatever remains in the target. For example, when inferring from |
| 68514 | // string to 'string | T', make a lower priority inference of string for T. |
| 68515 | inferWithPriority(source, target, 1 /* InferencePriority.NakedTypeVariable */); |
| 68516 | return; |
| 68517 | } |
| 68518 | source = getUnionType(sources); |
| 68519 | } |
| 68520 | else if (target.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(target.types, function (t) { return !!getInferenceInfoForType(t) || (isGenericMappedType(t) && !!getInferenceInfoForType(getHomomorphicTypeVariable(t) || neverType)); })) { |
| 68521 | // We reduce intersection types only when they contain naked type parameters. For example, when |
| 68522 | // inferring from 'string[] & { extra: any }' to 'string[] & T' we want to remove string[] and |
| 68523 | // infer { extra: any } for T. But when inferring to 'string[] & Iterable<T>' we want to keep the |
| 68524 | // string[] on the source side and infer string for T. |
| 68525 | // Likewise, we consider a homomorphic mapped type constrainted to the target type parameter as similar to a "naked type variable" |
no test coverage detected
searching dependent graphs…