From e0596ad9b80e80569236c4d681b5f8faaba71d5b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 7 Feb 2018 15:53:43 -0800 Subject: [PATCH] Improve contextual type skip in checkObjectLiteral It is still super hacky --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 866c282c3e3..7d27b525a76 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14755,7 +14755,7 @@ namespace ts { const isInJSFile = isInJavaScriptFile(node); // TODO: Might need to skip if isDeclarationOfDefaultedJavascriptContainerExpression(node.parent.parent) instead of just checking node.properties.length > 0 // (actually, it would be better not to skip contextual typing at all, but to do that I need to avoid the checking loop another way) - const contextualType = node.properties.length > 0 && getApparentTypeOfContextualType(node); + const contextualType = (!isInJSFile || node.properties.length > 0) && getApparentTypeOfContextualType(node); const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); const isJSObjectLiteral = !contextualType && isInJSFile;