Skip to content

Commit

Permalink
Revert "Fixed an issue with contextual type for intersection properti…
Browse files Browse the repository at this point in the history
…es (#48668)" (#50279)

This reverts commit 9236e39.
  • Loading branch information
RyanCavanaugh committed Aug 12, 2022
1 parent 8783da8 commit adf26ff
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 256 deletions.
34 changes: 4 additions & 30 deletions src/compiler/checker.ts
Expand Up @@ -27130,37 +27130,16 @@ namespace ts {
}

function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) {
return mapType(type, (t): Type | undefined => {
if (t.flags & TypeFlags.Intersection) {
const intersection = t as IntersectionType;
let newTypes = mapDefined(intersection.types, getTypeOfConcretePropertyOfContextualType);
if (newTypes.length > 0) {
return getIntersectionType(newTypes);
}
newTypes = mapDefined(intersection.types, getTypeOfApplicableIndexInfoOfContextualType);
if (newTypes.length > 0) {
return getIntersectionType(newTypes);
}
return undefined;
}
const concretePropertyType = getTypeOfConcretePropertyOfContextualType(t);
if (concretePropertyType) {
return concretePropertyType;
}
return getTypeOfApplicableIndexInfoOfContextualType(t);
}, /*noReductions*/ true);

function getTypeOfConcretePropertyOfContextualType(t: Type) {
return mapType(type, t => {
if (isGenericMappedType(t) && !t.declaration.nameType) {
const constraint = getConstraintTypeFromMappedType(t);
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
return substituteIndexedMappedType(t, propertyNameType);
}
return undefined;
}
if (t.flags & TypeFlags.StructuredType) {
else if (t.flags & TypeFlags.StructuredType) {
const prop = getPropertyOfType(t, name);
if (prop) {
return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop);
Expand All @@ -27171,15 +27150,10 @@ namespace ts {
return restType;
}
}
return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
}
return undefined;
}
function getTypeOfApplicableIndexInfoOfContextualType(t: Type) {
if (!(t.flags & TypeFlags.StructuredType)) {
return undefined;
}
return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
}
}, /*noReductions*/ true);
}

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit adf26ff

Please sign in to comment.