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