Add parentheses around keyof in declaration emit

When needed. Use InElementType flag to determine this.
This commit is contained in:
Nathan Shively-Sanders
2017-06-13 13:59:38 -07:00
parent 2a6575c36f
commit 21166f4824

View File

@@ -3233,9 +3233,15 @@ namespace ts {
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
}
else if (type.flags & TypeFlags.Index) {
if (flags & TypeFormatFlags.InElementType) {
writePunctuation(writer, SyntaxKind.OpenParenToken);
}
writer.writeKeyword("keyof");
writeSpace(writer);
writeType((<IndexType>type).type, TypeFormatFlags.InElementType);
if (flags & TypeFormatFlags.InElementType) {
writePunctuation(writer, SyntaxKind.CloseParenToken);
}
}
else if (type.flags & TypeFlags.IndexedAccess) {
writeType((<IndexedAccessType>type).objectType, TypeFormatFlags.InElementType);