From 21166f48246d28294d4a3cbcd30e9bc8f2d73c6d 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 db0e4e1575d..385e025f4bf 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);