MCPcopy Create free account
hub / github.com/nodejs/node / inferFromAnnotatedParameters

Function inferFromAnnotatedParameters

test/fixtures/snapshot/typescript.js:77668–77690  ·  view source on GitHub ↗
(signature, context, inferenceContext)

Source from the content-addressed store, hash-verified

77666 return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
77667 }
77668 function inferFromAnnotatedParameters(signature, context, inferenceContext) {
77669 var len = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0);
77670 for (var i = 0; i < len; i++) {
77671 var declaration = signature.parameters[i].valueDeclaration;
77672 if (declaration.type) {
77673 var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
77674 if (typeNode) {
77675 inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
77676 }
77677 }
77678 }
77679 var restType = getEffectiveRestType(context);
77680 if (restType && restType.flags & 262144 /* TypeFlags.TypeParameter */) {
77681 // The contextual signature has a generic rest parameter. We first instantiate the contextual
77682 // signature (without fixing type parameters) and assign types to contextually typed parameters.
77683 var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
77684 assignContextualParameterTypes(signature, instantiatedContext);
77685 // We then infer from a tuple type representing the parameters that correspond to the contextual
77686 // rest parameter.
77687 var restPos = getParameterCount(context) - 1;
77688 inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
77689 }
77690 }
77691 function assignContextualParameterTypes(signature, context) {
77692 if (context.typeParameters) {
77693 if (!signature.typeParameters) {

Calls 9

inferTypesFunction · 0.85
getTypeFromTypeNodeFunction · 0.85
getTypeAtPositionFunction · 0.85
getEffectiveRestTypeFunction · 0.85
instantiateSignatureFunction · 0.85
getParameterCountFunction · 0.85
getRestTypeAtPositionFunction · 0.85

Tested by

no test coverage detected