Merge pull request #27490 from Microsoft/indexedAccessConstraint

Limit unsound indexed access type relations
This commit is contained in:
Anders Hejlsberg
2018-10-03 10:58:45 -07:00
committed by GitHub
14 changed files with 868 additions and 781 deletions

View File

@@ -11897,8 +11897,9 @@ namespace ts {
}
}
else if (target.flags & TypeFlags.IndexedAccess) {
// A type S is related to a type T[K] if S is related to C, where C is the base constraint of T[K]
if (relation !== identityRelation) {
// A type S is related to a type T[K], where T and K aren't both type variables, if S is related to C,
// where C is the base constraint of T[K]
if (relation !== identityRelation && !(isGenericObjectType((<IndexedAccessType>target).objectType) && isGenericIndexType((<IndexedAccessType>target).indexType))) {
const constraint = getBaseConstraintOfType(target);
if (constraint && constraint !== target) {
if (result = isRelatedTo(source, constraint, reportErrors)) {