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

Function mapTypesByKeyProperty

test/fixtures/snapshot/typescript.js:69447–69481  ·  view source on GitHub ↗
(types, name)

Source from the content-addressed store, hash-verified

69445 // has a non-literal type or if less than 10 or less than 50% of the constituents have a unique key.
69446 // Entries with duplicate keys have unknownType as the value.
69447 function mapTypesByKeyProperty(types, name) {
69448 var map = new ts.Map();
69449 var count = 0;
69450 var _loop_23 = function (type) {
69451 if (type.flags & (524288 /* TypeFlags.Object */ | 2097152 /* TypeFlags.Intersection */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */)) {
69452 var discriminant = getTypeOfPropertyOfType(type, name);
69453 if (discriminant) {
69454 if (!isLiteralType(discriminant)) {
69455 return { value: undefined };
69456 }
69457 var duplicate_1 = false;
69458 forEachType(discriminant, function (t) {
69459 var id = getTypeId(getRegularTypeOfLiteralType(t));
69460 var existing = map.get(id);
69461 if (!existing) {
69462 map.set(id, type);
69463 }
69464 else if (existing !== unknownType) {
69465 map.set(id, unknownType);
69466 duplicate_1 = true;
69467 }
69468 });
69469 if (!duplicate_1)
69470 count++;
69471 }
69472 }
69473 };
69474 for (var _i = 0, types_16 = types; _i < types_16.length; _i++) {
69475 var type = types_16[_i];
69476 var state_9 = _loop_23(type);
69477 if (typeof state_9 === "object")
69478 return state_9.value;
69479 }
69480 return count >= 10 && count * 2 >= types.length ? map : undefined;
69481 }
69482 // Return the name of a discriminant property for which it was possible and feasible to construct a map of
69483 // constituent types keyed by the literal types of the property by that name in each constituent type.
69484 function getKeyPropertyName(unionType) {

Callers 1

getKeyPropertyNameFunction · 0.85

Calls 1

_loop_23Function · 0.85

Tested by

no test coverage detected