@@ -18452,32 +18452,6 @@ namespace ts {
18452
18452
return false;
18453
18453
}
18454
18454
18455
- // Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
18456
- // type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
18457
- // a possible discriminant if its type differs in the constituents of containing union type, and if every
18458
- // choice is a unit type or a union of unit types.
18459
- function containsMatchingReferenceDiscriminant(source: Node, target: Node) {
18460
- let name;
18461
- return isAccessExpression(target) &&
18462
- containsMatchingReference(source, target.expression) &&
18463
- (name = getAccessedPropertyName(target)) !== undefined &&
18464
- isDiscriminantProperty(getDeclaredTypeOfReference(target.expression), name);
18465
- }
18466
-
18467
- function getDeclaredTypeOfReference(expr: Node): Type | undefined {
18468
- if (expr.kind === SyntaxKind.Identifier) {
18469
- return getTypeOfSymbol(getResolvedSymbol(<Identifier>expr));
18470
- }
18471
- if (isAccessExpression(expr)) {
18472
- const type = getDeclaredTypeOfReference(expr.expression);
18473
- if (type) {
18474
- const propName = getAccessedPropertyName(expr);
18475
- return propName !== undefined ? getTypeOfPropertyOfType(type, propName) : undefined;
18476
- }
18477
- }
18478
- return undefined;
18479
- }
18480
-
18481
18455
function isDiscriminantProperty(type: Type | undefined, name: __String) {
18482
18456
if (type && type.flags & TypeFlags.Union) {
18483
18457
const prop = getUnionOrIntersectionProperty(<UnionType>type, name);
@@ -19509,9 +19483,6 @@ namespace ts {
19509
19483
type = narrowTypeByDiscriminant(type, expr as AccessExpression,
19510
19484
t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd));
19511
19485
}
19512
- else if (containsMatchingReferenceDiscriminant(reference, expr)) {
19513
- type = declaredType;
19514
- }
19515
19486
}
19516
19487
return createFlowType(type, isIncomplete(flowType));
19517
19488
}
@@ -19696,9 +19667,6 @@ namespace ts {
19696
19667
if (isMatchingReferenceDiscriminant(expr, declaredType)) {
19697
19668
return narrowTypeByDiscriminant(type, <AccessExpression>expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy));
19698
19669
}
19699
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
19700
- return declaredType;
19701
- }
19702
19670
return type;
19703
19671
}
19704
19672
@@ -19758,9 +19726,6 @@ namespace ts {
19758
19726
if (isMatchingReferenceDiscriminant(right, declaredType)) {
19759
19727
return narrowTypeByDiscriminant(type, <AccessExpression>right, t => narrowTypeByEquality(t, operator, left, assumeTrue));
19760
19728
}
19761
- if (containsMatchingReferenceDiscriminant(reference, left) || containsMatchingReferenceDiscriminant(reference, right)) {
19762
- return declaredType;
19763
- }
19764
19729
break;
19765
19730
case SyntaxKind.InstanceOfKeyword:
19766
19731
return narrowTypeByInstanceof(type, expr, assumeTrue);
@@ -20172,9 +20137,6 @@ namespace ts {
20172
20137
if (isMatchingReferenceDiscriminant(expr, declaredType)) {
20173
20138
return narrowTypeByDiscriminant(type, <AccessExpression>expr, t => getTypeWithFacts(t, assumePresent ? TypeFacts.NEUndefinedOrNull : TypeFacts.EQUndefinedOrNull));
20174
20139
}
20175
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
20176
- return declaredType;
20177
- }
20178
20140
return type;
20179
20141
}
20180
20142
}
0 commit comments