From e71afc32ad8cb4d1e48444fb38a0a2da4d39f989 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 24 Apr 2018 10:02:34 -0700 Subject: [PATCH] Reinstate type simplification for 'keyof T[K]' as target in relation --- src/compiler/checker.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 75f8715fca7..4e1d71c3d7a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10482,11 +10482,14 @@ namespace ts { } } // A type S is assignable to keyof T if S is assignable to keyof C, where C is the - // constraint of T. - const constraint = getConstraintForRelation((target).type); - if (constraint) { - if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors)) { - return result; + // simplified form of T or, if T doesn't simplify, the constraint of T. + if (relation !== definitelyAssignableRelation) { + const simplified = getSimplifiedType((target).type); + const constraint = simplified !== (target).type ? simplified : getConstraintOfType((target).type); + if (constraint) { + if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors)) { + return result; + } } } }