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

Function inferInstantiationFromUsage

test/fixtures/snapshot/typescript.js:157418–157433  ·  view source on GitHub ↗

* inference is limited to * 1. generic types with a single parameter * 2. inference to/from calls with a single signature

(type, usage)

Source from the content-addressed store, hash-verified

157416 * 2. inference to/from calls with a single signature
157417 */
157418 function inferInstantiationFromUsage(type, usage) {
157419 if (!(ts.getObjectFlags(type) & 4 /* ObjectFlags.Reference */) || !usage.properties) {
157420 return type;
157421 }
157422 var generic = type.target;
157423 var singleTypeParameter = ts.singleOrUndefined(generic.typeParameters);
157424 if (!singleTypeParameter)
157425 return type;
157426 var types = [];
157427 usage.properties.forEach(function (propUsage, name) {
157428 var genericPropertyType = checker.getTypeOfPropertyOfType(generic, name);
157429 ts.Debug.assert(!!genericPropertyType, "generic should have all the properties of its reference.");
157430 types.push.apply(types, inferTypeParameters(genericPropertyType, combineFromUsage(propUsage), singleTypeParameter));
157431 });
157432 return builtinConstructors[type.symbol.escapedName](combineTypes(types));
157433 }
157434 function inferTypeParameters(genericType, usageType, typeParameter) {
157435 if (genericType === typeParameter) {
157436 return [usageType];

Callers 1

Calls 6

inferTypeParametersFunction · 0.85
combineFromUsageFunction · 0.85
combineTypesFunction · 0.85
assertMethod · 0.80
forEachMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected