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

Function getInferredType

test/fixtures/snapshot/typescript.js:69148–69196  ·  view source on GitHub ↗
(context, index)

Source from the content-addressed store, hash-verified

69146 return getWidenedType(unwidenedType);
69147 }
69148 function getInferredType(context, index) {
69149 var inference = context.inferences[index];
69150 if (!inference.inferredType) {
69151 var inferredType = void 0;
69152 var signature = context.signature;
69153 if (signature) {
69154 var inferredCovariantType_1 = inference.candidates ? getCovariantInference(inference, signature) : undefined;
69155 if (inference.contraCandidates) {
69156 // If we have both co- and contra-variant inferences, we prefer the contra-variant inference
69157 // unless the co-variant inference is a subtype of some contra-variant inference and not 'never'.
69158 inferredType = inferredCovariantType_1 && !(inferredCovariantType_1.flags & 131072 /* TypeFlags.Never */) &&
69159 ts.some(inference.contraCandidates, function (t) { return isTypeSubtypeOf(inferredCovariantType_1, t); }) ?
69160 inferredCovariantType_1 : getContravariantInference(inference);
69161 }
69162 else if (inferredCovariantType_1) {
69163 inferredType = inferredCovariantType_1;
69164 }
69165 else if (context.flags & 1 /* InferenceFlags.NoDefault */) {
69166 // We use silentNeverType as the wildcard that signals no inferences.
69167 inferredType = silentNeverType;
69168 }
69169 else {
69170 // Infer either the default or the empty object type when no inferences were
69171 // made. It is important to remember that in this case, inference still
69172 // succeeds, meaning there is no error for not having inference candidates. An
69173 // inference error only occurs when there are *conflicting* candidates, i.e.
69174 // candidates with no common supertype.
69175 var defaultType = getDefaultFromTypeParameter(inference.typeParameter);
69176 if (defaultType) {
69177 // Instantiate the default type. Any forward reference to a type
69178 // parameter should be instantiated to the empty object type.
69179 inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
69180 }
69181 }
69182 }
69183 else {
69184 inferredType = getTypeFromInference(inference);
69185 }
69186 inference.inferredType = inferredType || getDefaultTypeArgumentType(!!(context.flags & 2 /* InferenceFlags.AnyDefault */));
69187 var constraint = getConstraintOfTypeParameter(inference.typeParameter);
69188 if (constraint) {
69189 var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
69190 if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
69191 inference.inferredType = inferredType = instantiatedConstraint;
69192 }
69193 }
69194 }
69195 return inference.inferredType;
69196 }
69197 function getDefaultTypeArgumentType(isInJavaScriptFile) {
69198 return isInJavaScriptFile ? anyType : unknownType;
69199 }

Callers 2

mapToInferredTypeFunction · 0.85
getInferredTypesFunction · 0.85

Calls 12

getCovariantInferenceFunction · 0.85
isTypeSubtypeOfFunction · 0.85
instantiateTypeFunction · 0.85
mergeTypeMappersFunction · 0.85
getTypeFromInferenceFunction · 0.85
getTypeWithThisArgumentFunction · 0.85
someMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…