diff --git a/src/services/completions.ts b/src/services/completions.ts index 1f1007f2f6150..1b00fde028c71 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3024,7 +3024,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); diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern16.ts b/tests/cases/fourslash/completionListInObjectBindingPattern16.ts new file mode 100644 index 0000000000000..87e534182d7ff --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern16.ts @@ -0,0 +1,18 @@ +/// + +// @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"] });