Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify index and object types when obtaining indexed access constraint
  • Loading branch information
ahejlsberg committed May 22, 2019
1 parent 3745694 commit 8120094
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8120094

Please sign in to comment.