MCPcopy Index your code
hub / github.com/nodejs/node / inferTypes

Function inferTypes

test/fixtures/snapshot/typescript.js:68456–69096  ·  view source on GitHub ↗
(inferences, originalSource, originalTarget, priority, contravariant)

Source from the content-addressed store, hash-verified

68454 }
68455 }
68456 function inferTypes(inferences, originalSource, originalTarget, priority, contravariant) {
68457 if (priority === void 0) { priority = 0; }
68458 if (contravariant === void 0) { contravariant = false; }
68459 var bivariant = false;
68460 var propagationType;
68461 var inferencePriority = 2048 /* InferencePriority.MaxValue */;
68462 var allowComplexConstraintInference = true;
68463 var visited;
68464 var sourceStack;
68465 var targetStack;
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

Callers 11

_loop_18Function · 0.85
structuredTypeRelatedToFunction · 0.85
inferReverseMappedTypeFunction · 0.85
inferJsxTypeArgumentsFunction · 0.85
inferTypeArgumentsFunction · 0.85
combineFromUsageFunction · 0.85

Calls 8

inferFromTypesFunction · 0.85
combineFromUsageFunction · 0.85
inferStructuralTypeFunction · 0.85
mapMethod · 0.65
pushMethod · 0.45
lengthMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…