Skip to content

Commit 112e4b1

Browse files
committed
Addressed PR feedback
1 parent 6cfa64d commit 112e4b1

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/services/services.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,9 +3506,16 @@ namespace ts {
35063506
// through type declaration or inference.
35073507
// Also proceed if rootDeclaration is parameter and if its containing function expression\arrow function is contextually typed -
35083508
// type of parameter will flow in from the contextual type of the function
3509-
if (rootDeclaration.initializer ||
3510-
rootDeclaration.type ||
3511-
(rootDeclaration.kind === SyntaxKind.Parameter && isExpression(rootDeclaration.parent) && typeChecker.getContextualType(<Expression>rootDeclaration.parent))) {
3509+
let canGetType = !!(rootDeclaration.initializer || rootDeclaration.type);
3510+
if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) {
3511+
if (isExpression(rootDeclaration.parent)) {
3512+
canGetType = !!typeChecker.getContextualType(<Expression>rootDeclaration.parent);
3513+
}
3514+
else if (rootDeclaration.parent.kind === SyntaxKind.MethodDeclaration || rootDeclaration.parent.kind === SyntaxKind.SetAccessor) {
3515+
canGetType = isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(<Expression>rootDeclaration.parent.parent);
3516+
}
3517+
}
3518+
if (canGetType) {
35123519
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
35133520
existingMembers = (<BindingPattern>objectLikeContainer).elements;
35143521
}

tests/cases/fourslash/objectLiteralBindingInParameter.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@
66

77
////[<I>null].reduce(({/*2*/}, b) => b);
88

9+
////interface Foo {
10+
//// m(x: { x1: number, x2: number }): void;
11+
//// prop: I;
12+
////}
13+
////let x: Foo = {
14+
//// m({ /*3*/ }) {
15+
//// },
16+
//// get prop(): I { return undefined; },
17+
//// set prop({ /*4*/ }) {
18+
//// }
19+
////};
20+
921
goTo.marker("1");
1022
verify.completionListContains("x1");
1123
verify.completionListContains("x2");
1224

1325
goTo.marker("2");
1426
verify.completionListContains("x1");
27+
verify.completionListContains("x2");
28+
29+
goTo.marker("3");
30+
verify.completionListContains("x1");
31+
verify.completionListContains("x2");
32+
33+
goTo.marker("4");
34+
verify.completionListContains("x1");
1535
verify.completionListContains("x2");

0 commit comments

Comments
 (0)