@@ -26811,7 +26811,27 @@ namespace ts {
26811
26811
}
26812
26812
26813
26813
function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) {
26814
- return mapType(type, function propertyOfContextualTypeMapper(t): Type | undefined {
26814
+ return mapType(type, (t): Type | undefined => {
26815
+ if (t.flags & TypeFlags.Intersection) {
26816
+ const intersection = t as IntersectionType;
26817
+ let newTypes = mapDefined(intersection.types, getTypeOfConcretePropertyOfContextualType);
26818
+ if (newTypes.length > 0) {
26819
+ return getIntersectionType(newTypes);
26820
+ }
26821
+ newTypes = mapDefined(intersection.types, getTypeOfApplicableIndexInfoOfContextualType);
26822
+ if (newTypes.length > 0) {
26823
+ return getIntersectionType(newTypes);
26824
+ }
26825
+ return undefined;
26826
+ }
26827
+ const concretePropertyType = getTypeOfConcretePropertyOfContextualType(t);
26828
+ if (concretePropertyType) {
26829
+ return concretePropertyType;
26830
+ }
26831
+ return getTypeOfApplicableIndexInfoOfContextualType(t);
26832
+ }, /*noReductions*/ true);
26833
+
26834
+ function getTypeOfConcretePropertyOfContextualType(t: Type) {
26815
26835
if (isGenericMappedType(t) && !t.declaration.nameType) {
26816
26836
const constraint = getConstraintTypeFromMappedType(t);
26817
26837
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
@@ -26821,14 +26841,6 @@ namespace ts {
26821
26841
}
26822
26842
return undefined;
26823
26843
}
26824
- if (t.flags & TypeFlags.Intersection) {
26825
- const intersection = t as IntersectionType;
26826
- const newTypes = intersection.types.map(propertyOfContextualTypeMapper).filter((t): t is Type => !!t);
26827
- if (newTypes.length === 0) {
26828
- return undefined;
26829
- }
26830
- return getIntersectionType(newTypes);
26831
- }
26832
26844
if (t.flags & TypeFlags.StructuredType) {
26833
26845
const prop = getPropertyOfType(t, name);
26834
26846
if (prop) {
@@ -26840,10 +26852,15 @@ namespace ts {
26840
26852
return restType;
26841
26853
}
26842
26854
}
26843
- return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
26844
26855
}
26845
26856
return undefined;
26846
- }, /*noReductions*/ true);
26857
+ }
26858
+ function getTypeOfApplicableIndexInfoOfContextualType(t: Type) {
26859
+ if (!(t.flags & TypeFlags.StructuredType)) {
26860
+ return undefined;
26861
+ }
26862
+ return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
26863
+ }
26847
26864
}
26848
26865
26849
26866
// In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of
0 commit comments