Skip to content

Commit 49a12dc

Browse files
authored
fix(47081): show completion list in parenthesized object literal arguments (#47104)
1 parent 8907d7a commit 49a12dc

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/services/completions.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -3913,9 +3913,14 @@ namespace ts.Completions {
39133913
if (type) {
39143914
return type;
39153915
}
3916-
if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken && node === node.parent.left) {
3916+
const parent = walkUpParenthesizedExpressions(node.parent);
3917+
if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken && node === parent.left) {
39173918
// Object literal is assignment pattern: ({ | } = x)
3918-
return typeChecker.getTypeAtLocation(node.parent);
3919+
return typeChecker.getTypeAtLocation(parent);
3920+
}
3921+
if (isExpression(parent)) {
3922+
// f(() => (({ | })));
3923+
return typeChecker.getContextualType(parent);
39193924
}
39203925
return undefined;
39213926
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////type Foo = { foo: boolean };
4+
////function f<T>(shape: Foo): any;
5+
////function f<T>(shape: () => Foo): any;
6+
////function f(arg: any) {
7+
//// return arg;
8+
////}
9+
////
10+
////f({ /*1*/ });
11+
////f(() => ({ /*2*/ }));
12+
////f(() => (({ /*3*/ })));
13+
14+
verify.completions({
15+
marker: ["1", "2", "3"],
16+
exact: ["foo"]
17+
});

0 commit comments

Comments
 (0)