@@ -27124,37 +27124,16 @@ namespace ts {
27124
27124
}
27125
27125
27126
27126
function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) {
27127
- return mapType(type, (t): Type | undefined => {
27128
- if (t.flags & TypeFlags.Intersection) {
27129
- const intersection = t as IntersectionType;
27130
- let newTypes = mapDefined(intersection.types, getTypeOfConcretePropertyOfContextualType);
27131
- if (newTypes.length > 0) {
27132
- return getIntersectionType(newTypes);
27133
- }
27134
- newTypes = mapDefined(intersection.types, getTypeOfApplicableIndexInfoOfContextualType);
27135
- if (newTypes.length > 0) {
27136
- return getIntersectionType(newTypes);
27137
- }
27138
- return undefined;
27139
- }
27140
- const concretePropertyType = getTypeOfConcretePropertyOfContextualType(t);
27141
- if (concretePropertyType) {
27142
- return concretePropertyType;
27143
- }
27144
- return getTypeOfApplicableIndexInfoOfContextualType(t);
27145
- }, /*noReductions*/ true);
27146
-
27147
- function getTypeOfConcretePropertyOfContextualType(t: Type) {
27127
+ return mapType(type, t => {
27148
27128
if (isGenericMappedType(t) && !t.declaration.nameType) {
27149
27129
const constraint = getConstraintTypeFromMappedType(t);
27150
27130
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
27151
27131
const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
27152
27132
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
27153
27133
return substituteIndexedMappedType(t, propertyNameType);
27154
27134
}
27155
- return undefined;
27156
27135
}
27157
- if (t.flags & TypeFlags.StructuredType) {
27136
+ else if (t.flags & TypeFlags.StructuredType) {
27158
27137
const prop = getPropertyOfType(t, name);
27159
27138
if (prop) {
27160
27139
return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop);
@@ -27165,15 +27144,10 @@ namespace ts {
27165
27144
return restType;
27166
27145
}
27167
27146
}
27147
+ return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
27168
27148
}
27169
27149
return undefined;
27170
- }
27171
- function getTypeOfApplicableIndexInfoOfContextualType(t: Type) {
27172
- if (!(t.flags & TypeFlags.StructuredType)) {
27173
- return undefined;
27174
- }
27175
- return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
27176
- }
27150
+ }, /*noReductions*/ true);
27177
27151
}
27178
27152
27179
27153
// In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of
0 commit comments