diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3c8c0be77c7..89daf7ea0cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3216,11 +3216,11 @@ namespace ts { } } - // A variable declared in a for..in statement is always of type string + // A variable declared in a for..in statement is of type string, or of type keyof T when the + // right hand expression is of a type parameter type. if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { - // const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); - // return indexType.flags & TypeFlags.Index ? indexType : stringType; - return stringType; + const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); + return indexType.flags & TypeFlags.Index ? indexType : stringType; } if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) {