Skip to content

Commit 21166f4

Browse files
committed
Add parentheses around keyof in declaration emit
When needed. Use InElementType flag to determine this.
1 parent 2a6575c commit 21166f4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,9 +3233,15 @@ namespace ts {
32333233
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
32343234
}
32353235
else if (type.flags & TypeFlags.Index) {
3236+
if (flags & TypeFormatFlags.InElementType) {
3237+
writePunctuation(writer, SyntaxKind.OpenParenToken);
3238+
}
32363239
writer.writeKeyword("keyof");
32373240
writeSpace(writer);
32383241
writeType((<IndexType>type).type, TypeFormatFlags.InElementType);
3242+
if (flags & TypeFormatFlags.InElementType) {
3243+
writePunctuation(writer, SyntaxKind.CloseParenToken);
3244+
}
32393245
}
32403246
else if (type.flags & TypeFlags.IndexedAccess) {
32413247
writeType((<IndexedAccessType>type).objectType, TypeFormatFlags.InElementType);

0 commit comments

Comments
 (0)