fix(47081): show completion list in parenthesized object literal arguments (#47104)

This commit is contained in:
Oleksandr T 2022-03-25 00:30:26 +02:00 committed by GitHub
parent 8907d7a675
commit 49a12dcbbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -3913,9 +3913,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;
}

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
////type Foo = { foo: boolean };
////function f<T>(shape: Foo): any;
////function f<T>(shape: () => Foo): any;
////function f(arg: any) {
//// return arg;
////}
////
////f({ /*1*/ });
////f(() => ({ /*2*/ }));
////f(() => (({ /*3*/ })));
verify.completions({
marker: ["1", "2", "3"],
exact: ["foo"]
});