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

Function compareSignaturesRelated

test/fixtures/snapshot/typescript.js:64342–64458  ·  view source on GitHub ↗

* See signatureRelatedTo, compareSignaturesIdentical

(source, target, checkMode, reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers)

Source from the content-addressed store, hash-verified

64340 * See signatureRelatedTo, compareSignaturesIdentical
64341 */
64342 function compareSignaturesRelated(source, target, checkMode, reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers) {
64343 // TODO (drosen): De-duplicate code between related functions.
64344 if (source === target) {
64345 return -1 /* Ternary.True */;
64346 }
64347 if (isAnySignature(target)) {
64348 return -1 /* Ternary.True */;
64349 }
64350 var targetCount = getParameterCount(target);
64351 var sourceHasMoreParameters = !hasEffectiveRestParameter(target) &&
64352 (checkMode & 8 /* SignatureCheckMode.StrictArity */ ? hasEffectiveRestParameter(source) || getParameterCount(source) > targetCount : getMinArgumentCount(source) > targetCount);
64353 if (sourceHasMoreParameters) {
64354 return 0 /* Ternary.False */;
64355 }
64356 if (source.typeParameters && source.typeParameters !== target.typeParameters) {
64357 target = getCanonicalSignature(target);
64358 source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
64359 }
64360 var sourceCount = getParameterCount(source);
64361 var sourceRestType = getNonArrayRestType(source);
64362 var targetRestType = getNonArrayRestType(target);
64363 if (sourceRestType || targetRestType) {
64364 void instantiateType(sourceRestType || targetRestType, reportUnreliableMarkers);
64365 }
64366 var kind = target.declaration ? target.declaration.kind : 0 /* SyntaxKind.Unknown */;
64367 var strictVariance = !(checkMode & 3 /* SignatureCheckMode.Callback */) && strictFunctionTypes && kind !== 169 /* SyntaxKind.MethodDeclaration */ &&
64368 kind !== 168 /* SyntaxKind.MethodSignature */ && kind !== 171 /* SyntaxKind.Constructor */;
64369 var result = -1 /* Ternary.True */;
64370 var sourceThisType = getThisTypeOfSignature(source);
64371 if (sourceThisType && sourceThisType !== voidType) {
64372 var targetThisType = getThisTypeOfSignature(target);
64373 if (targetThisType) {
64374 // void sources are assignable to anything.
64375 var related = !strictVariance && compareTypes(sourceThisType, targetThisType, /*reportErrors*/ false)
64376 || compareTypes(targetThisType, sourceThisType, reportErrors);
64377 if (!related) {
64378 if (reportErrors) {
64379 errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible);
64380 }
64381 return 0 /* Ternary.False */;
64382 }
64383 result &= related;
64384 }
64385 }
64386 var paramCount = sourceRestType || targetRestType ? Math.min(sourceCount, targetCount) : Math.max(sourceCount, targetCount);
64387 var restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
64388 for (var i = 0; i < paramCount; i++) {
64389 var sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
64390 var targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
64391 if (sourceType && targetType) {
64392 // In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
64393 // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
64394 // they naturally relate only contra-variantly). However, if the source and target parameters both have
64395 // function types with a single call signature, we know we are relating two callback parameters. In
64396 // that case it is sufficient to only relate the parameters of the signatures co-variantly because,
64397 // similar to return values, callback parameters are output positions. This means that a Promise<T>,
64398 // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
64399 // with respect to T.

Callers 2

isSignatureAssignableToFunction · 0.85
signatureRelatedToFunction · 0.85

Calls 15

isAnySignatureFunction · 0.85
getParameterCountFunction · 0.85
getMinArgumentCountFunction · 0.85
getCanonicalSignatureFunction · 0.85
getNonArrayRestTypeFunction · 0.85
instantiateTypeFunction · 0.85
getThisTypeOfSignatureFunction · 0.85
getRestTypeAtPositionFunction · 0.85
tryGetTypeAtPositionFunction · 0.85
getSingleCallSignatureFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…