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

Function getNarrowableTypeForReference

test/fixtures/snapshot/typescript.js:71515–71527  ·  view source on GitHub ↗
(type, reference, checkMode)

Source from the content-addressed store, hash-verified

71513 return contextualType && !isGenericType(contextualType);
71514 }
71515 function getNarrowableTypeForReference(type, reference, checkMode) {
71516 // When the type of a reference is or contains an instantiable type with a union type constraint, and
71517 // when the reference is in a constraint position (where it is known we'll obtain the apparent type) or
71518 // has a contextual type containing no top-level instantiables (meaning constraints will determine
71519 // assignability), we substitute constraints for all instantiables in the type of the reference to give
71520 // control flow analysis an opportunity to narrow it further. For example, for a reference of a type
71521 // parameter type 'T extends string | undefined' with a contextual type 'string', we substitute
71522 // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
71523 var substituteConstraints = !(checkMode && checkMode & 2 /* CheckMode.Inferential */) &&
71524 someType(type, isGenericTypeWithUnionConstraint) &&
71525 (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71526 return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* TypeFlags.Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71527 }
71528 function isExportOrExportExpression(location) {
71529 return !!ts.findAncestor(location, function (n) {
71530 var parent = n.parent;

Callers 3

getInitialOrAssignedTypeFunction · 0.85
checkIdentifierFunction · 0.85

Calls 5

someTypeFunction · 0.85
isConstraintPositionFunction · 0.85
mapTypeFunction · 0.85
getBaseConstraintOrTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…