Enable retrieving the type of a binding property name when an initializer/type annotation is present.

This commit is contained in:
Daniel Rosenwasser
2015-07-15 15:56:13 -07:00
parent 5c6a3d73b9
commit fdd1f30a95
2 changed files with 27 additions and 7 deletions

View File

@@ -3232,8 +3232,19 @@ namespace ts {
// We are *only* completing on properties from the type being destructured.
isNewIdentifierLocation = false;
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
existingMembers = (<BindingPattern>objectLikeContainer).elements;
let rootDeclaration = getRootDeclaration(objectLikeContainer.parent);
if (isVariableLike(rootDeclaration)) {
// 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) {
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
existingMembers = (<BindingPattern>objectLikeContainer).elements;
}
}
else {
Debug.fail("Root declaration is not variable-like.")
}
}
else {
Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind);