Merge pull request #16505 from Microsoft/decl-emit-parenthesize-keyof

Add parentheses around keyof in declaration emit when needed
This commit is contained in:
Nathan Shively-Sanders
2017-06-13 14:17:49 -07:00
committed by GitHub
5 changed files with 68 additions and 0 deletions

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);