show completion in destructured parameter if containing function was contextually typed#7567
Conversation
…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))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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({ $ }) {
}
};|
Can you also add a test for an object binding pattern parameter in an object literal method which is contextually typed? |
|
👍 |
|
@DanielRosenwasser any other somments? |
|
👍 |
show completion in destructured parameter if containing function was contextually typed
Fixes #7558