Skip to content

Commit d01a6ad

Browse files
RyanCavanaughtypescript-bot
authored andcommitted
Cherry-pick PR microsoft#50279 into release-4.8
Component commits: eff4406 Revert "Fixed an issue with contextual type for intersection properties (microsoft#48668)" This reverts commit 9236e39.
1 parent 60b5167 commit d01a6ad

5 files changed

+4
-256
lines changed

src/compiler/checker.ts

+4-30
Original file line numberDiff line numberDiff line change
@@ -27124,37 +27124,16 @@ namespace ts {
2712427124
}
2712527125

2712627126
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 => {
2714827128
if (isGenericMappedType(t) && !t.declaration.nameType) {
2714927129
const constraint = getConstraintTypeFromMappedType(t);
2715027130
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
2715127131
const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
2715227132
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
2715327133
return substituteIndexedMappedType(t, propertyNameType);
2715427134
}
27155-
return undefined;
2715627135
}
27157-
if (t.flags & TypeFlags.StructuredType) {
27136+
else if (t.flags & TypeFlags.StructuredType) {
2715827137
const prop = getPropertyOfType(t, name);
2715927138
if (prop) {
2716027139
return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop);
@@ -27165,15 +27144,10 @@ namespace ts {
2716527144
return restType;
2716627145
}
2716727146
}
27147+
return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
2716827148
}
2716927149
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);
2717727151
}
2717827152

2717927153
// In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of

tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.js

-42
This file was deleted.

tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols

-82
This file was deleted.

tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types

-73
This file was deleted.

tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts

-29
This file was deleted.

0 commit comments

Comments
 (0)