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

Function narrowTypeByDiscriminant

test/fixtures/snapshot/typescript.js:70800–70816  ·  view source on GitHub ↗
(type, access, narrowType)

Source from the content-addressed store, hash-verified

70798 return undefined;
70799 }
70800 function narrowTypeByDiscriminant(type, access, narrowType) {
70801 var propName = getAccessedPropertyName(access);
70802 if (propName === undefined) {
70803 return type;
70804 }
70805 var removeNullable = strictNullChecks && ts.isOptionalChain(access) && maybeTypeOfKind(type, 98304 /* TypeFlags.Nullable */);
70806 var propType = getTypeOfPropertyOfType(removeNullable ? getTypeWithFacts(type, 2097152 /* TypeFacts.NEUndefinedOrNull */) : type, propName);
70807 if (!propType) {
70808 return type;
70809 }
70810 propType = removeNullable ? getOptionalType(propType) : propType;
70811 var narrowedPropType = narrowType(propType);
70812 return filterType(type, function (t) {
70813 var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
70814 return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType);
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);

Calls 9

getAccessedPropertyNameFunction · 0.85
maybeTypeOfKindFunction · 0.85
getTypeOfPropertyOfTypeFunction · 0.85
getTypeWithFactsFunction · 0.85
getOptionalTypeFunction · 0.85
narrowTypeFunction · 0.85
filterTypeFunction · 0.85
isTypeComparableToFunction · 0.85

Tested by

no test coverage detected