Skip to content

Commit 1710df5

Browse files
committed
Type of for-in variable is keyof T when object type is a type parameter
1 parent c555848 commit 1710df5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: src/compiler/checker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3216,11 +3216,11 @@ namespace ts {
32163216
}
32173217
}
32183218

3219-
// A variable declared in a for..in statement is always of type string
3219+
// A variable declared in a for..in statement is of type string, or of type keyof T when the
3220+
// right hand expression is of a type parameter type.
32203221
if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
3221-
// const indexType = getIndexType(checkNonNullExpression((<ForInStatement>declaration.parent.parent).expression));
3222-
// return indexType.flags & TypeFlags.Index ? indexType : stringType;
3223-
return stringType;
3222+
const indexType = getIndexType(checkNonNullExpression((<ForInStatement>declaration.parent.parent).expression));
3223+
return indexType.flags & TypeFlags.Index ? indexType : stringType;
32243224
}
32253225

32263226
if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) {

0 commit comments

Comments
 (0)