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

Function combineTypes

test/fixtures/snapshot/typescript.js:157267–157295  ·  view source on GitHub ↗
(inferences)

Source from the content-addressed store, hash-verified

157265 return combineTypes(inferTypes(usage));
157266 }
157267 function combineTypes(inferences) {
157268 if (!inferences.length)
157269 return checker.getAnyType();
157270 // 1. string or number individually override string | number
157271 // 2. non-any, non-void overrides any or void
157272 // 3. non-nullable, non-any, non-void, non-anonymous overrides anonymous types
157273 var stringNumber = checker.getUnionType([checker.getStringType(), checker.getNumberType()]);
157274 var priorities = [
157275 {
157276 high: function (t) { return t === checker.getStringType() || t === checker.getNumberType(); },
157277 low: function (t) { return t === stringNumber; }
157278 },
157279 {
157280 high: function (t) { return !(t.flags & (1 /* TypeFlags.Any */ | 16384 /* TypeFlags.Void */)); },
157281 low: function (t) { return !!(t.flags & (1 /* TypeFlags.Any */ | 16384 /* TypeFlags.Void */)); }
157282 },
157283 {
157284 high: function (t) { return !(t.flags & (98304 /* TypeFlags.Nullable */ | 1 /* TypeFlags.Any */ | 16384 /* TypeFlags.Void */)) && !(ts.getObjectFlags(t) & 16 /* ObjectFlags.Anonymous */); },
157285 low: function (t) { return !!(ts.getObjectFlags(t) & 16 /* ObjectFlags.Anonymous */); }
157286 }
157287 ];
157288 var good = removeLowPriorityInferences(inferences, priorities);
157289 var anons = good.filter(function (i) { return ts.getObjectFlags(i) & 16 /* ObjectFlags.Anonymous */; });
157290 if (anons.length) {
157291 good = good.filter(function (i) { return !(ts.getObjectFlags(i) & 16 /* ObjectFlags.Anonymous */); });
157292 good.push(combineAnonymousTypes(anons));
157293 }
157294 return checker.getWidenedType(checker.getUnionType(good.map(checker.getBaseTypeOfLiteralType), 2 /* UnionReduction.Subtype */));
157295 }
157296 function combineAnonymousTypes(anons) {
157297 if (anons.length === 1) {
157298 return anons[0];

Callers 6

singleFunction · 0.85
parametersFunction · 0.85
thisParameterFunction · 0.85
combineFromUsageFunction · 0.85
_loop_16Function · 0.85

Calls 5

combineAnonymousTypesFunction · 0.85
filterMethod · 0.65
mapMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…