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

Function findMostOverlappyType

test/fixtures/snapshot/typescript.js:89207–89233  ·  view source on GitHub ↗
(source, unionTarget)

Source from the content-addressed store, hash-verified

89205 }
89206 }
89207 function findMostOverlappyType(source, unionTarget) {
89208 var bestMatch;
89209 if (!(source.flags & (131068 /* TypeFlags.Primitive */ | 406847488 /* TypeFlags.InstantiablePrimitive */))) {
89210 var matchingCount = 0;
89211 for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
89212 var target = _a[_i];
89213 if (!(target.flags & (131068 /* TypeFlags.Primitive */ | 406847488 /* TypeFlags.InstantiablePrimitive */))) {
89214 var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
89215 if (overlap.flags & 4194304 /* TypeFlags.Index */) {
89216 // perfect overlap of keys
89217 return target;
89218 }
89219 else if (isUnitType(overlap) || overlap.flags & 1048576 /* TypeFlags.Union */) {
89220 // We only want to account for literal types otherwise.
89221 // If we have a union of index types, it seems likely that we
89222 // needed to elaborate between two generic mapped types anyway.
89223 var len = overlap.flags & 1048576 /* TypeFlags.Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
89224 if (len >= matchingCount) {
89225 bestMatch = target;
89226 matchingCount = len;
89227 }
89228 }
89229 }
89230 }
89231 }
89232 return bestMatch;
89233 }
89234 function filterPrimitivesIfContainsNonPrimitive(type) {
89235 if (maybeTypeOfKind(type, 67108864 /* TypeFlags.NonPrimitive */)) {
89236 var result = filterType(type, function (t) { return !(t.flags & 131068 /* TypeFlags.Primitive */); });

Callers 1

getBestMatchingTypeFunction · 0.85

Calls 3

getIntersectionTypeFunction · 0.85
getIndexTypeFunction · 0.85
isUnitTypeFunction · 0.85

Tested by

no test coverage detected