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

Function narrowTypeByTruthiness

test/fixtures/snapshot/typescript.js:70841–70854  ·  view source on GitHub ↗
(type, expr, assumeTrue)

Source from the content-addressed store, hash-verified

70839 return narrowTypeByDiscriminant(type, access, function (t) { return narrowTypeBySwitchOnDiscriminant(t, switchStatement, clauseStart, clauseEnd); });
70840 }
70841 function narrowTypeByTruthiness(type, expr, assumeTrue) {
70842 if (isMatchingReference(reference, expr)) {
70843 return type.flags & 2 /* TypeFlags.Unknown */ && assumeTrue ? nonNullUnknownType :
70844 getTypeWithFacts(type, assumeTrue ? 4194304 /* TypeFacts.Truthy */ : 8388608 /* TypeFacts.Falsy */);
70845 }
70846 if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70847 type = getTypeWithFacts(type, 2097152 /* TypeFacts.NEUndefinedOrNull */);
70848 }
70849 var access = getDiscriminantPropertyAccess(expr, type);
70850 if (access) {
70851 return narrowTypeByDiscriminant(type, access, function (t) { return getTypeWithFacts(t, assumeTrue ? 4194304 /* TypeFacts.Truthy */ : 8388608 /* TypeFacts.Falsy */); });
70852 }
70853 return type;
70854 }
70855 function isTypePresencePossible(type, propName, assumeTrue) {
70856 var prop = getPropertyOfType(type, propName);
70857 if (prop) {

Callers 2

narrowTypeFunction · 0.85

Calls 5

isMatchingReferenceFunction · 0.85
getTypeWithFactsFunction · 0.85
narrowTypeByDiscriminantFunction · 0.85

Tested by

no test coverage detected