From 1710df5f28fed8dfa7630978c873ed1bf6ee3983 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 12:56:32 -0800 Subject: [PATCH] Type of for-in variable is keyof T when object type is a type parameter --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) {