feat(48743): allow autocompletion in parameter object destructuring in JavaScript (#48757)

This commit is contained in:
Oleksandr T
2022-04-28 00:00:01 +03:00
committed by GitHub
parent d45012c5e2
commit 717a1be3c9
2 changed files with 19 additions and 1 deletions

View File

@@ -3062,7 +3062,7 @@ namespace ts.Completions {
// through type declaration or inference.
// Also proceed if rootDeclaration is a 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
let canGetType = hasInitializer(rootDeclaration) || hasType(rootDeclaration) || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement;
let canGetType = hasInitializer(rootDeclaration) || !!getEffectiveTypeAnnotationNode(rootDeclaration) || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement;
if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) {
if (isExpression(rootDeclaration.parent)) {
canGetType = !!typeChecker.getContextualType(rootDeclaration.parent as Expression);

View File

@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @checkJs: true
// @filename: a.js
/////**
//// * @typedef Foo
//// * @property {number} a
//// * @property {string} b
//// */
////
/////**
//// * @param {Foo} options
//// */
////function f({ /**/ }) {}
verify.completions({ marker: "", exact: ["a", "b"] });