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

Function narrowTypeByDiscriminantProperty

test/fixtures/snapshot/typescript.js:70817–70830  ·  view source on GitHub ↗
(type, access, operator, value, assumeTrue)

Source from the content-addressed store, hash-verified

70815 });
70816 }
70817 function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) {
70818 if ((operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */) && type.flags & 1048576 /* TypeFlags.Union */) {
70819 var keyPropertyName = getKeyPropertyName(type);
70820 if (keyPropertyName && keyPropertyName === getAccessedPropertyName(access)) {
70821 var candidate = getConstituentTypeForKeyType(type, getTypeOfExpression(value));
70822 if (candidate) {
70823 return operator === (assumeTrue ? 36 /* SyntaxKind.EqualsEqualsEqualsToken */ : 37 /* SyntaxKind.ExclamationEqualsEqualsToken */) ? candidate :
70824 isUnitType(getTypeOfPropertyOfType(candidate, keyPropertyName) || unknownType) ? removeType(type, candidate) :
70825 type;
70826 }
70827 }
70828 }
70829 return narrowTypeByDiscriminant(type, access, function (t) { return narrowTypeByEquality(t, operator, value, assumeTrue); });
70830 }
70831 function narrowTypeBySwitchOnDiscriminantProperty(type, access, switchStatement, clauseStart, clauseEnd) {
70832 if (clauseStart < clauseEnd && type.flags & 1048576 /* TypeFlags.Union */ && getKeyPropertyName(type) === getAccessedPropertyName(access)) {
70833 var clauseTypes = getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd);

Callers 1

Calls 9

getKeyPropertyNameFunction · 0.85
getAccessedPropertyNameFunction · 0.85
getTypeOfExpressionFunction · 0.85
isUnitTypeFunction · 0.85
getTypeOfPropertyOfTypeFunction · 0.85
removeTypeFunction · 0.85
narrowTypeByDiscriminantFunction · 0.85
narrowTypeByEqualityFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…