@@ -26789,7 +26789,27 @@ namespace ts {
26789
26789
}
26790
26790
26791
26791
function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) {
26792
- return mapType(type, function propertyOfContextualTypeMapper(t): Type | undefined {
26792
+ return mapType(type, (t): Type | undefined => {
26793
+ if (t.flags & TypeFlags.Intersection) {
26794
+ const intersection = t as IntersectionType;
26795
+ let newTypes = intersection.types.map(getTypeOfConcretePropertyOfContextualType).filter((t): t is Type => !!t);
26796
+ if (newTypes.length > 0) {
26797
+ return getIntersectionType(newTypes);
26798
+ }
26799
+ newTypes = intersection.types.map(getTypeOfApplicableIndexInfoOfContextualType).filter((t): t is Type => !!t);
26800
+ if (newTypes.length > 0) {
26801
+ return getIntersectionType(newTypes);
26802
+ }
26803
+ return undefined;
26804
+ }
26805
+ const concretePropertyType = getTypeOfConcretePropertyOfContextualType(t);
26806
+ if (concretePropertyType) {
26807
+ return concretePropertyType;
26808
+ }
26809
+ return getTypeOfApplicableIndexInfoOfContextualType(t);
26810
+ }, /*noReductions*/ true);
26811
+
26812
+ function getTypeOfConcretePropertyOfContextualType(t: Type) {
26793
26813
if (isGenericMappedType(t) && !t.declaration.nameType) {
26794
26814
const constraint = getConstraintTypeFromMappedType(t);
26795
26815
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
@@ -26799,14 +26819,6 @@ namespace ts {
26799
26819
}
26800
26820
return undefined;
26801
26821
}
26802
- if (t.flags & TypeFlags.Intersection) {
26803
- const intersection = t as IntersectionType;
26804
- const newTypes = intersection.types.map(propertyOfContextualTypeMapper).filter((t): t is Type => !!t);
26805
- if (newTypes.length === 0) {
26806
- return undefined;
26807
- }
26808
- return getIntersectionType(newTypes);
26809
- }
26810
26822
if (t.flags & TypeFlags.StructuredType) {
26811
26823
const prop = getPropertyOfType(t, name);
26812
26824
if (prop) {
@@ -26818,10 +26830,15 @@ namespace ts {
26818
26830
return restType;
26819
26831
}
26820
26832
}
26821
- return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
26822
26833
}
26823
26834
return undefined;
26824
- }, /*noReductions*/ true);
26835
+ }
26836
+ function getTypeOfApplicableIndexInfoOfContextualType(t: Type) {
26837
+ if (!(t.flags & TypeFlags.StructuredType)) {
26838
+ return undefined;
26839
+ }
26840
+ return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
26841
+ }
26825
26842
}
26826
26843
26827
26844
// In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of
0 commit comments