Skip to content

show completion in destructured parameter if containing function was contextually typed#7567

Merged
vladima merged 2 commits into
masterfrom
contextual-type-parameters
Mar 17, 2016
Merged

show completion in destructured parameter if containing function was contextually typed#7567
vladima merged 2 commits into
masterfrom
contextual-type-parameters

Conversation

@vladima

@vladima vladima commented Mar 17, 2016

Copy link
Copy Markdown
Contributor

Fixes #7558

@sandersn

Copy link
Copy Markdown
Member

👍

Comment thread src/services/services.ts Outdated
// 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))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct in the case of object literal methods. This will also break if @sandersn's work goes in to contextually type subclass properties.

Can't you just check if you're in a parameter and you have a contextual type? Why do you need to bring the parent into this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object literal properties are handled in the branch above.
The check if parent has contextual type is necessary to make sure that the type that we'll obtain from getTypeAtLocation is backed up by something (contextual type of the function) and not just implied by the shape of object binding pattern

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline: need to support cases when completion is requested at position $

interface Foo { m(x: { a: number, b: number }): void }
let x: Foo = {
    m({ $ }) {
    }
};

@DanielRosenwasser

Copy link
Copy Markdown
Member

Can you also add a test for an object binding pattern parameter in an object literal method which is contextually typed?

@mhegazy

mhegazy commented Mar 17, 2016

Copy link
Copy Markdown
Contributor

👍

@vladima

vladima commented Mar 17, 2016

Copy link
Copy Markdown
Contributor Author

@DanielRosenwasser any other somments?

@DanielRosenwasser

Copy link
Copy Markdown
Member

👍

vladima added a commit that referenced this pull request Mar 17, 2016
show completion in destructured parameter if containing function was contextually typed
@vladima vladima merged commit 279fec7 into master Mar 17, 2016
@vladima vladima deleted the contextual-type-parameters branch March 17, 2016 23:30
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants