show completion in destructured parameter if containing function was contextually typed

This commit is contained in:
Vladimir Matveev
2016-03-17 11:37:52 -07:00
parent 51e8f7dd7a
commit 6cfa64daa3
2 changed files with 20 additions and 1 deletions

View File

@@ -3504,7 +3504,11 @@ namespace ts {
// We don't want to complete using the type acquired by the shape
// of the binding pattern; we are only interested in types acquired
// through type declaration or inference.
if (rootDeclaration.initializer || rootDeclaration.type) {
// Also proceed if rootDeclaration is parameter and if its containing function expression\arrow function is contextually typed -
// type of parameter will flow in from the contextual type of the function
if (rootDeclaration.initializer ||
rootDeclaration.type ||
(rootDeclaration.kind === SyntaxKind.Parameter && isExpression(rootDeclaration.parent) && typeChecker.getContextualType(<Expression>rootDeclaration.parent))) {
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
existingMembers = (<BindingPattern>objectLikeContainer).elements;
}

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>
////interface I { x1: number; x2: string }
////function f(cb: (ev: I) => any) { }
////f(({/*1*/}) => 0);
////[<I>null].reduce(({/*2*/}, b) => b);
goTo.marker("1");
verify.completionListContains("x1");
verify.completionListContains("x2");
goTo.marker("2");
verify.completionListContains("x1");
verify.completionListContains("x2");