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

Function narrowTypeByCallExpression

test/fixtures/snapshot/typescript.js:71303–71322  ·  view source on GitHub ↗
(type, callExpression, assumeTrue)

Source from the content-addressed store, hash-verified

71301 getIntersectionType([type, candidate]);
71302 }
71303 function narrowTypeByCallExpression(type, callExpression, assumeTrue) {
71304 if (hasMatchingArgument(callExpression, reference)) {
71305 var signature = assumeTrue || !ts.isCallChain(callExpression) ? getEffectsSignature(callExpression) : undefined;
71306 var predicate = signature && getTypePredicateOfSignature(signature);
71307 if (predicate && (predicate.kind === 0 /* TypePredicateKind.This */ || predicate.kind === 1 /* TypePredicateKind.Identifier */)) {
71308 return narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue);
71309 }
71310 }
71311 if (containsMissingType(type) && ts.isAccessExpression(reference) && ts.isPropertyAccessExpression(callExpression.expression)) {
71312 var callAccess = callExpression.expression;
71313 if (isMatchingReference(reference.expression, getReferenceCandidate(callAccess.expression)) &&
71314 ts.isIdentifier(callAccess.name) && callAccess.name.escapedText === "hasOwnProperty" && callExpression.arguments.length === 1) {
71315 var argument = callExpression.arguments[0];
71316 if (ts.isStringLiteralLike(argument) && getAccessedPropertyName(reference) === ts.escapeLeadingUnderscores(argument.text)) {
71317 return getTypeWithFacts(type, assumeTrue ? 524288 /* TypeFacts.NEUndefined */ : 65536 /* TypeFacts.EQUndefined */);
71318 }
71319 }
71320 }
71321 return type;
71322 }
71323 function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) {
71324 // Don't narrow from 'any' if the predicate type is exactly 'Object' or 'Function'
71325 if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) {

Callers 1

narrowTypeFunction · 0.85

Calls 9

hasMatchingArgumentFunction · 0.85
getEffectsSignatureFunction · 0.85
containsMissingTypeFunction · 0.85
isMatchingReferenceFunction · 0.85
getReferenceCandidateFunction · 0.85
getAccessedPropertyNameFunction · 0.85
getTypeWithFactsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…