Skip to content

Commit fc2f16c

Browse files
committed
Treat unconstrained T[K] the same as unconstrained T
1 parent 732661c commit fc2f16c

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10670,23 +10670,8 @@ namespace ts {
1067010670
}
1067110671
}
1067210672

10673-
if (source.flags & TypeFlags.TypeParameter) {
10674-
let constraint = getConstraintForRelation(<TypeParameter>source);
10675-
// A type parameter with no constraint is not related to the non-primitive object type.
10676-
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
10677-
if (!constraint || constraint.flags & TypeFlags.Any) {
10678-
constraint = emptyObjectType;
10679-
}
10680-
// Report constraint errors only if the constraint is not the empty object type
10681-
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
10682-
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
10683-
errorInfo = saveErrorInfo;
10684-
return result;
10685-
}
10686-
}
10687-
}
10688-
else if (source.flags & TypeFlags.IndexedAccess) {
10689-
if (target.flags & TypeFlags.IndexedAccess) {
10673+
if (source.flags & TypeFlags.TypeVariable) {
10674+
if (source.flags & TypeFlags.IndexedAccess && target.flags & TypeFlags.IndexedAccess) {
1069010675
// A type S[K] is related to a type T[J] if S is related to T and K is related to J.
1069110676
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
1069210677
result &= isRelatedTo((<IndexedAccessType>source).indexType, (<IndexedAccessType>target).indexType, reportErrors);
@@ -10696,11 +10681,15 @@ namespace ts {
1069610681
return result;
1069710682
}
1069810683
}
10699-
// A type S[K] is related to a type T if C is related to T, where C is the
10700-
// constraint of S[K].
10701-
const constraint = getConstraintForRelation(<IndexedAccessType>source);
10702-
if (constraint) {
10703-
if (result = isRelatedTo(constraint, target, reportErrors)) {
10684+
let constraint = getConstraintForRelation(<TypeParameter>source);
10685+
// A type variable with no constraint is not related to the non-primitive object type.
10686+
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
10687+
if (!constraint || constraint.flags & TypeFlags.Any) {
10688+
constraint = emptyObjectType;
10689+
}
10690+
// Report constraint errors only if the constraint is not the empty object type
10691+
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
10692+
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
1070410693
errorInfo = saveErrorInfo;
1070510694
return result;
1070610695
}

0 commit comments

Comments
 (0)