diff --git a/src/services/completions.ts b/src/services/completions.ts index ca265f268f035..407bccafa320c 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3750,9 +3750,14 @@ namespace ts.Completions { if (type) { return type; } - if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken && node === node.parent.left) { + const parent = walkUpParenthesizedExpressions(node.parent); + if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken && node === parent.left) { // Object literal is assignment pattern: ({ | } = x) - return typeChecker.getTypeAtLocation(node.parent); + return typeChecker.getTypeAtLocation(parent); + } + if (isExpression(parent)) { + // f(() => (({ | }))); + return typeChecker.getContextualType(parent); } return undefined; } diff --git a/tests/cases/fourslash/completionListInObjectLiteral7.ts b/tests/cases/fourslash/completionListInObjectLiteral7.ts new file mode 100644 index 0000000000000..6f933ffb470af --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectLiteral7.ts @@ -0,0 +1,17 @@ +/// + +////type Foo = { foo: boolean }; +////function f(shape: Foo): any; +////function f(shape: () => Foo): any; +////function f(arg: any) { +//// return arg; +////} +//// +////f({ /*1*/ }); +////f(() => ({ /*2*/ })); +////f(() => (({ /*3*/ }))); + +verify.completions({ + marker: ["1", "2", "3"], + exact: ["foo"] +});