From 1ebdcc6fb810e728bac291d1a3e43bd4a54ee5e8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 1 Feb 2022 10:11:39 -0800 Subject: [PATCH] Fix inlay hint crash for jsdoc function type syntax (#47684) * Fix inlay hint crash for jsdoc function type syntax Parameters in JSDoc function types do not have names. The type does not reflect this. This PR fixes the crash; I'll see how much churn it causes to fix the type as well. Fixes #47606 * make inlay hints test smaller --- src/compiler/checker.ts | 3 +++ tests/cases/fourslash/inlayHintsCrash1.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/cases/fourslash/inlayHintsCrash1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cffd5acc456..82b2880ba14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31508,6 +31508,9 @@ namespace ts { } function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): [parameterName: __String, isRestParameter: boolean] | undefined { + if (signature.declaration?.kind === SyntaxKind.JSDocFunctionType) { + return undefined; + } const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); if (pos < paramCount) { const param = signature.parameters[pos]; diff --git a/tests/cases/fourslash/inlayHintsCrash1.ts b/tests/cases/fourslash/inlayHintsCrash1.ts new file mode 100644 index 00000000000..793bac5eff2 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsCrash1.ts @@ -0,0 +1,14 @@ +/// +// @allowJs: true +// @checkJs: true +// @Filename: foo.js +//// /** +//// * @param {function(string): boolean} f +//// */ +//// function doThing(f) { +//// f(100) +//// } +verify.getInlayHints([], undefined, { + includeInlayVariableTypeHints: true, + includeInlayParameterNameHints: "all", +});