From 43d47de74dad468be328af32c6a2776f55b10bbc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 13 Jun 2017 13:59:38 -0700 Subject: [PATCH] Add parentheses around keyof in declaration emit When needed. Use InElementType flag to determine this. --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b7dd84f7716..338dd72d52d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3233,9 +3233,15 @@ namespace ts { writer.writeStringLiteral(literalTypeToString(type)); } else if (type.flags & TypeFlags.Index) { + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } writer.writeKeyword("keyof"); writeSpace(writer); writeType((type).type, TypeFormatFlags.InElementType); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } } else if (type.flags & TypeFlags.IndexedAccess) { writeType((type).objectType, TypeFormatFlags.InElementType);