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

Function unionOrIntersectionRelatedTo

test/fixtures/snapshot/typescript.js:65266–65300  ·  view source on GitHub ↗
(source, target, reportErrors, intersectionState)

Source from the content-addressed store, hash-verified

65264 return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
65265 }
65266 function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
65267 // Note that these checks are specifically ordered to produce correct results. In particular,
65268 // we need to deconstruct unions before intersections (because unions are always at the top),
65269 // and we need to handle "each" relations before "some" relations for the same kind of type.
65270 if (source.flags & 1048576 /* TypeFlags.Union */) {
65271 return relation === comparableRelation ?
65272 someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* TypeFlags.Primitive */), intersectionState) :
65273 eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* TypeFlags.Primitive */), intersectionState);
65274 }
65275 if (target.flags & 1048576 /* TypeFlags.Union */) {
65276 return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* TypeFlags.Primitive */) && !(target.flags & 131068 /* TypeFlags.Primitive */));
65277 }
65278 if (target.flags & 2097152 /* TypeFlags.Intersection */) {
65279 return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* IntersectionState.Target */);
65280 }
65281 // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
65282 // constraints of all non-primitive types in the source into a new intersection. We do this because the
65283 // intersection may further constrain the constraints of the non-primitive types. For example, given a type
65284 // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
65285 // appear to be comparable to '2'.
65286 if (relation === comparableRelation && target.flags & 131068 /* TypeFlags.Primitive */) {
65287 var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
65288 if (constraints !== source.types) {
65289 source = getIntersectionType(constraints);
65290 if (!(source.flags & 2097152 /* TypeFlags.Intersection */)) {
65291 return isRelatedTo(source, target, 1 /* RecursionFlags.Source */, /*reportErrors*/ false);
65292 }
65293 }
65294 }
65295 // Check to see if any constituents of the intersection are immediately related to the target.
65296 // Don't report errors though. Elaborating on whether a source constituent is related to the target is
65297 // not actually useful and leads to some confusing error messages. Instead, we rely on the caller
65298 // checking whether the full intersection viewed as an object is related to the target.
65299 return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* IntersectionState.Source */);
65300 }
65301 function eachTypeRelatedToSomeType(source, target) {
65302 var result = -1 /* Ternary.True */;
65303 var sourceTypes = source.types;

Callers 2

isRelatedToFunction · 0.85
structuredTypeRelatedToFunction · 0.85

Calls 7

someTypeRelatedToTypeFunction · 0.85
eachTypeRelatedToTypeFunction · 0.85
typeRelatedToSomeTypeFunction · 0.85
typeRelatedToEachTypeFunction · 0.85
getIntersectionTypeFunction · 0.85
isRelatedToFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…