diff --git a/src/services/completions.ts b/src/services/completions.ts
index b7ac7e26925a4..eab6d030b01b4 100644
--- a/src/services/completions.ts
+++ b/src/services/completions.ts
@@ -1891,10 +1891,12 @@ namespace ts.Completions {
let existingMembers: readonly Declaration[] | undefined;
if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) {
- const instantiatedType = typeChecker.getContextualType(objectLikeContainer);
- const completionsType = instantiatedType && typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
- if (!instantiatedType || !completionsType) return GlobalsSearch.Fail;
- isNewIdentifierLocation = hasIndexSignature(instantiatedType || completionsType);
+ const instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
+ if (instantiatedType === undefined) {
+ return GlobalsSearch.Fail;
+ }
+ const completionsType = typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
+ isNewIdentifierLocation = hasIndexSignature(completionsType || instantiatedType);
typeMembers = getPropertiesForObjectExpression(instantiatedType, completionsType, objectLikeContainer, typeChecker);
existingMembers = objectLikeContainer.properties;
}
@@ -2830,4 +2832,15 @@ namespace ts.Completions {
function isStaticProperty(symbol: Symbol) {
return !!(symbol.valueDeclaration && getEffectiveModifierFlags(symbol.valueDeclaration) & ModifierFlags.Static && isClassLike(symbol.valueDeclaration.parent));
}
+
+ function tryGetObjectLiteralContextualType(node: ObjectLiteralExpression, typeChecker: TypeChecker) {
+ const type = typeChecker.getContextualType(node);
+ if (type) {
+ return type;
+ }
+ if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken) {
+ return typeChecker.getTypeAtLocation(node.parent);
+ }
+ return undefined;
+ }
}
diff --git a/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern1.ts b/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern1.ts
new file mode 100644
index 0000000000000..a39572ee39d30
--- /dev/null
+++ b/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern1.ts
@@ -0,0 +1,7 @@
+
+///
+
+////let x = { a: 1, b: 2 };
+////let y = ({ /**/ } = x, 1);
+
+verify.completions({ marker: "", exact: ["a", "b"] });
diff --git a/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern2.ts b/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern2.ts
new file mode 100644
index 0000000000000..315f4b78922b2
--- /dev/null
+++ b/tests/cases/fourslash/completionListInObjectLiteralAssignmentPattern2.ts
@@ -0,0 +1,7 @@
+
+///
+
+////let x = { a: 1, b: 2 };
+////let y = ({ a, /**/ } = x, 1);
+
+verify.completions({ marker: "", exact: ["b"] });