Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fixed an issue with contextual type for intersection properties" #50279

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.