Type of for-in variable is keyof T when object type is a type parameter

This commit is contained in:
Anders Hejlsberg 2016-11-21 12:56:32 -08:00
parent c5558482b7
commit 1710df5f28

View File

@ -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((<ForInStatement>declaration.parent.parent).expression));
// return indexType.flags & TypeFlags.Index ? indexType : stringType;
return stringType;
const indexType = getIndexType(checkNonNullExpression((<ForInStatement>declaration.parent.parent).expression));
return indexType.flags & TypeFlags.Index ? indexType : stringType;
}
if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) {