From 79d3f2e680e48949581bafd8c9302c8e29939cbb Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Chauhan Date: Wed, 4 Nov 2026 12:43:04 +0530 Subject: [PATCH] Add fourslash test for JSDoc @this/@param types in JS files Covers completions, hover, and signature help using JSDoc @this and @param types in a JS file (see #65167). --- .../tests/jsdocThisAndParamTypesInJs_test.go | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tsc/internal/fourslash/tests/jsdocThisAndParamTypesInJs_test.go diff --git a/tsc/internal/fourslash/tests/jsdocThisAndParamTypesInJs_test.go b/tsc/internal/fourslash/tests/jsdocThisAndParamTypesInJs_test.go new file mode 100644 index 0000000000000..705951df4c505 --- /dev/null +++ b/tsc/internal/fourslash/tests/jsdocThisAndParamTypesInJs_test.go @@ -0,0 +1,57 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + . "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +// JSDoc `@this` and `@param` types in JS files should be used by completions, hover, and signature help. +func TestJsdocThisAndParamTypesInJs(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @filename: /a.js +/** + * @this {{ id: string, click: () => void }} + * @param {{ name: string }} p + */ +function h(p/*paramHover*/) { + this./*thisCompletions*/; + p./*paramCompletions*/; +} + +/** + * @param {string} a + * @param {number} b + */ +function f(a, b) {} +f(/*signatureHelp*/);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + + f.VerifyCompletions(t, "thisCompletions", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"click", "id"}, + }, + }) + f.VerifyCompletions(t, "paramCompletions", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"name"}, + }, + }) + f.VerifyQuickInfoAt(t, "paramHover", "(parameter) p: {\n name: string;\n}", "") + f.GoToMarker(t, "signatureHelp") + f.VerifySignatureHelp(t, fourslash.VerifySignatureHelpOptions{Text: "f(a: string, b: number): void"}) +}