Skip to content

Commit 6cfa64d

Browse files
committed
show completion in destructured parameter if containing function was contextually typed
1 parent 51e8f7d commit 6cfa64d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/services/services.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,11 @@ namespace ts {
35043504
// We don't want to complete using the type acquired by the shape
35053505
// of the binding pattern; we are only interested in types acquired
35063506
// through type declaration or inference.
3507-
if (rootDeclaration.initializer || rootDeclaration.type) {
3507+
// Also proceed if rootDeclaration is parameter and if its containing function expression\arrow function is contextually typed -
3508+
// 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))) {
35083512
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
35093513
existingMembers = (<BindingPattern>objectLikeContainer).elements;
35103514
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////interface I { x1: number; x2: string }
4+
////function f(cb: (ev: I) => any) { }
5+
////f(({/*1*/}) => 0);
6+
7+
////[<I>null].reduce(({/*2*/}, b) => b);
8+
9+
goTo.marker("1");
10+
verify.completionListContains("x1");
11+
verify.completionListContains("x2");
12+
13+
goTo.marker("2");
14+
verify.completionListContains("x1");
15+
verify.completionListContains("x2");

0 commit comments

Comments
 (0)