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

Function getKeyPropertyName

test/fixtures/snapshot/typescript.js:69484–69504  ·  view source on GitHub ↗
(unionType)

Source from the content-addressed store, hash-verified

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) {
69485 var types = unionType.types;
69486 // We only construct maps for unions with many non-primitive constituents.
69487 if (types.length < 10 || ts.getObjectFlags(unionType) & 32768 /* ObjectFlags.PrimitiveUnion */ ||
69488 ts.countWhere(types, function (t) { return !!(t.flags & (524288 /* TypeFlags.Object */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */)); }) < 10) {
69489 return undefined;
69490 }
69491 if (unionType.keyPropertyName === undefined) {
69492 // The candidate key property name is the name of the first property with a unit type in one of the
69493 // constituent types.
69494 var keyPropertyName = ts.forEach(types, function (t) {
69495 return t.flags & (524288 /* TypeFlags.Object */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */) ?
69496 ts.forEach(getPropertiesOfType(t), function (p) { return isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined; }) :
69497 undefined;
69498 });
69499 var mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);
69500 unionType.keyPropertyName = mapByKeyProperty ? keyPropertyName : "";
69501 unionType.constituentMap = mapByKeyProperty;
69502 }
69503 return unionType.keyPropertyName.length ? unionType.keyPropertyName : undefined;
69504 }
69505 // Given a union type for which getKeyPropertyName returned a non-undefined result, return the constituent
69506 // that corresponds to the given key type for that property name.
69507 function getConstituentTypeForKeyType(unionType, keyType) {

Calls 5

getPropertiesOfTypeFunction · 0.85
isUnitTypeFunction · 0.85
getTypeOfSymbolFunction · 0.85
mapTypesByKeyPropertyFunction · 0.85
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…