Skip to content

Commit e71afc3

Browse files
committed
Reinstate type simplification for 'keyof T[K]' as target in relation
1 parent b1baca5 commit e71afc3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10482,11 +10482,14 @@ namespace ts {
1048210482
}
1048310483
}
1048410484
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
10485-
// constraint of T.
10486-
const constraint = getConstraintForRelation((<IndexType>target).type);
10487-
if (constraint) {
10488-
if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors)) {
10489-
return result;
10485+
// simplified form of T or, if T doesn't simplify, the constraint of T.
10486+
if (relation !== definitelyAssignableRelation) {
10487+
const simplified = getSimplifiedType((<IndexType>target).type);
10488+
const constraint = simplified !== (<IndexType>target).type ? simplified : getConstraintOfType((<IndexType>target).type);
10489+
if (constraint) {
10490+
if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors)) {
10491+
return result;
10492+
}
1049010493
}
1049110494
}
1049210495
}

0 commit comments

Comments
 (0)