From 5150682a58b8043ffa1c9049d92c0321609eb361 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 18 Feb 2022 15:58:09 -0800 Subject: [PATCH] Only suggest `@param` codefixes in TS (#47959) * Only issue @param suggestions with codefixes in TS Previously, there were 2 JS errors that were issued as suggestions in TS files. But there was no codefix for these errors, and the errors were incorrect in TS. This PR only issues the JS-specific errors on JS files. * Minimise test --- src/compiler/checker.ts | 8 +++++--- .../cases/fourslash/jsdocParam_suggestion1.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/jsdocParam_suggestion1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 88798760f3a46..cb52a13176aca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -38650,9 +38650,9 @@ namespace ts { const containsArguments = containsArgumentsReference(node); if (containsArguments) { const lastJSDocParam = lastOrUndefined(jsdocParameters); - if (lastJSDocParam && isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression && + if (isJs && lastJSDocParam && isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression && lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) { - errorOrSuggestion(isJs, lastJSDocParam.name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, idText(lastJSDocParam.name)); + error(lastJSDocParam.name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, idText(lastJSDocParam.name)); } } else { @@ -38661,7 +38661,9 @@ namespace ts { return; } if (isQualifiedName(name)) { - errorOrSuggestion(isJs, name, Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, entityNameToString(name), entityNameToString(name.left)); + if (isJs) { + error(name, Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, entityNameToString(name), entityNameToString(name.left)); + } } else { errorOrSuggestion(isJs, name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, idText(name)); diff --git a/tests/cases/fourslash/jsdocParam_suggestion1.ts b/tests/cases/fourslash/jsdocParam_suggestion1.ts new file mode 100644 index 0000000000000..f3c5fca656682 --- /dev/null +++ b/tests/cases/fourslash/jsdocParam_suggestion1.ts @@ -0,0 +1,18 @@ +/// +// @Filename: a.ts +//// /** +//// * @param options - whatever +//// * @param options.zone - equally bad +//// */ +//// declare function bad(options: any): void +//// +//// /** +//// * @param {number} obtuse +//// */ +//// function worse(): void { +//// arguments +//// } + +goTo.file('a.ts') +verify.getSuggestionDiagnostics([]); +