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

Function narrowTypeByTypePredicate

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

Source from the content-addressed store, hash-verified

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))) {
71326 var predicateArgument = getTypePredicateArgument(predicate, callExpression);
71327 if (predicateArgument) {
71328 if (isMatchingReference(reference, predicateArgument)) {
71329 return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
71330 }
71331 if (strictNullChecks && assumeTrue && optionalChainContainsReference(predicateArgument, reference) &&
71332 !(getTypeFacts(predicate.type) & 65536 /* TypeFacts.EQUndefined */)) {
71333 type = getTypeWithFacts(type, 2097152 /* TypeFacts.NEUndefinedOrNull */);
71334 }
71335 var access = getDiscriminantPropertyAccess(predicateArgument, type);
71336 if (access) {
71337 return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, isTypeSubtypeOf); });
71338 }
71339 }
71340 }
71341 return type;
71342 }
71343 // Narrow the given type based on the given expression having the assumed boolean value. The returned type
71344 // will be a subtype or the same type as the argument.
71345 function narrowType(type, expr, assumeTrue) {

Callers 2

getTypeAtFlowCallFunction · 0.85

Calls 9

isTypeAnyFunction · 0.85
getTypePredicateArgumentFunction · 0.85
isMatchingReferenceFunction · 0.85
getNarrowedTypeFunction · 0.85
getTypeFactsFunction · 0.85
getTypeWithFactsFunction · 0.85
narrowTypeByDiscriminantFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…