Simplify index and object types when obtaining indexed access constraint

This commit is contained in:
Anders Hejlsberg
2019-05-22 06:49:49 -07:00
parent 374569447c
commit 8120094c81

View File

@@ -7657,15 +7657,20 @@ namespace ts {
return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : undefined;
}
function getSimplifiedTypeOrConstraint(type: Type) {
const simplified = getSimplifiedType(type, /*writing*/ false);
return simplified !== type ? simplified : getConstraintOfType(type);
}
function getConstraintFromIndexedAccess(type: IndexedAccessType) {
const indexConstraint = getConstraintOfType(type.indexType);
const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
if (indexConstraint && indexConstraint !== type.indexType) {
const indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint);
if (indexedAccess) {
return indexedAccess;
}
}
const objectConstraint = getConstraintOfType(type.objectType);
const objectConstraint = getSimplifiedTypeOrConstraint(type.objectType);
if (objectConstraint && objectConstraint !== type.objectType) {
return getIndexedAccessTypeOrUndefined(objectConstraint, type.indexType);
}