@@ -3160,8 +3160,8 @@ namespace ts {
3160
3160
return emptyArray;
3161
3161
}
3162
3162
3163
- // If the given type is an object type and that type has a property by the given name, return
3164
- // the symbol for that property. Otherwise return undefined.
3163
+ // If the given type is an object type and that type has a property by the given name,
3164
+ // return the symbol for that property.Otherwise return undefined.
3165
3165
function getPropertyOfObjectType(type: Type, name: string): Symbol {
3166
3166
if (type.flags & TypeFlags.ObjectType) {
3167
3167
let resolved = resolveStructuredTypeMembers(<ObjectType>type);
@@ -4464,7 +4464,7 @@ namespace ts {
4464
4464
let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
4465
4465
// identity relation does not use apparent type
4466
4466
let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
4467
- if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType) {
4467
+ if (sourceOrApparentType.flags & ( TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) {
4468
4468
if (result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors)) {
4469
4469
errorInfo = saveErrorInfo;
4470
4470
return result;
@@ -4595,7 +4595,7 @@ namespace ts {
4595
4595
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
4596
4596
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
4597
4597
// and issue an error. Otherwise, actually compare the structure of the two types.
4598
- function objectTypeRelatedTo(source: ObjectType , target: ObjectType , reportErrors: boolean): Ternary {
4598
+ function objectTypeRelatedTo(source: Type , target: Type , reportErrors: boolean): Ternary {
4599
4599
if (overflow) {
4600
4600
return Ternary.False;
4601
4601
}
@@ -4670,7 +4670,7 @@ namespace ts {
4670
4670
return result;
4671
4671
}
4672
4672
4673
- function propertiesRelatedTo(source: ObjectType , target: ObjectType , reportErrors: boolean): Ternary {
4673
+ function propertiesRelatedTo(source: Type , target: Type , reportErrors: boolean): Ternary {
4674
4674
if (relation === identityRelation) {
4675
4675
return propertiesIdenticalTo(source, target);
4676
4676
}
@@ -4753,7 +4753,10 @@ namespace ts {
4753
4753
return result;
4754
4754
}
4755
4755
4756
- function propertiesIdenticalTo(source: ObjectType, target: ObjectType): Ternary {
4756
+ function propertiesIdenticalTo(source: Type, target: Type): Ternary {
4757
+ if (!(source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType)) {
4758
+ return Ternary.False;
4759
+ }
4757
4760
let sourceProperties = getPropertiesOfObjectType(source);
4758
4761
let targetProperties = getPropertiesOfObjectType(target);
4759
4762
if (sourceProperties.length !== targetProperties.length) {
@@ -4774,7 +4777,7 @@ namespace ts {
4774
4777
return result;
4775
4778
}
4776
4779
4777
- function signaturesRelatedTo(source: ObjectType , target: ObjectType , kind: SignatureKind, reportErrors: boolean): Ternary {
4780
+ function signaturesRelatedTo(source: Type , target: Type , kind: SignatureKind, reportErrors: boolean): Ternary {
4778
4781
if (relation === identityRelation) {
4779
4782
return signaturesIdenticalTo(source, target, kind);
4780
4783
}
@@ -4900,7 +4903,7 @@ namespace ts {
4900
4903
return result & isRelatedTo(s, t, reportErrors);
4901
4904
}
4902
4905
4903
- function signaturesIdenticalTo(source: ObjectType , target: ObjectType , kind: SignatureKind): Ternary {
4906
+ function signaturesIdenticalTo(source: Type , target: Type , kind: SignatureKind): Ternary {
4904
4907
let sourceSignatures = getSignaturesOfType(source, kind);
4905
4908
let targetSignatures = getSignaturesOfType(target, kind);
4906
4909
if (sourceSignatures.length !== targetSignatures.length) {
@@ -4917,7 +4920,7 @@ namespace ts {
4917
4920
return result;
4918
4921
}
4919
4922
4920
- function stringIndexTypesRelatedTo(source: ObjectType , target: ObjectType , reportErrors: boolean): Ternary {
4923
+ function stringIndexTypesRelatedTo(source: Type , target: Type , reportErrors: boolean): Ternary {
4921
4924
if (relation === identityRelation) {
4922
4925
return indexTypesIdenticalTo(IndexKind.String, source, target);
4923
4926
}
@@ -4942,7 +4945,7 @@ namespace ts {
4942
4945
return Ternary.True;
4943
4946
}
4944
4947
4945
- function numberIndexTypesRelatedTo(source: ObjectType , target: ObjectType , reportErrors: boolean): Ternary {
4948
+ function numberIndexTypesRelatedTo(source: Type , target: Type , reportErrors: boolean): Ternary {
4946
4949
if (relation === identityRelation) {
4947
4950
return indexTypesIdenticalTo(IndexKind.Number, source, target);
4948
4951
}
@@ -4975,7 +4978,7 @@ namespace ts {
4975
4978
return Ternary.True;
4976
4979
}
4977
4980
4978
- function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType , target: ObjectType ): Ternary {
4981
+ function indexTypesIdenticalTo(indexKind: IndexKind, source: Type , target: Type ): Ternary {
4979
4982
let targetType = getIndexTypeOfType(target, indexKind);
4980
4983
let sourceType = getIndexTypeOfType(source, indexKind);
4981
4984
if (!sourceType && !targetType) {
@@ -6335,7 +6338,7 @@ namespace ts {
6335
6338
6336
6339
function getTypeOfPropertyOfContextualType(type: Type, name: string) {
6337
6340
return applyToContextualType(type, t => {
6338
- let prop = getPropertyOfObjectType (t, name);
6341
+ let prop = t.flags & TypeFlags.StructuredType ? getPropertyOfType (t, name) : undefined ;
6339
6342
return prop ? getTypeOfSymbol(prop) : undefined;
6340
6343
});
6341
6344
}
0 commit comments