microsoft / microsoft/TypeScript

JSDoc @type completion not working inside function argument

Open
#62,281 0 comments 0 reactions 0 assignees View on GitHub
Domain: JSDoc Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 Search Terms

jsdoc, completion

### 🕗 Version & Regression Information

Never seems to have worked

### ⏯ Playground Link

_No response_

### 💻 Code

JSDoc has some completion issues with completions like this:

```js
function someFunc(/** @type {^cursor here^} **/) {}
```

❌ Does not work - `@type` completion (in function argument) from `@import` with named argument
```
///

// @allowJS: true
// @checkJs: true
// @module: esnext

// @filename: ./a.ts
////export interface ABC {}

// @filename: ./b.js
/////** @import * as t from "./a" */
////function someFunc(/** @type {t./**/} */arg) {}

verify.completions({
marker: "",
includes: "ABC",
});
```

✅ Works - `@type` completion (in function argument) from `@typedef` and with named argument

```
///

// @allowJS: true
// @checkJs: true
// @module: esnext

// @filename: ./b.js
/////** @typedef {number} SomeNumber */
////function someFunc(/** @type {S/**/} */arg) {}

verify.completions({
marker: "",
includes: "SomeNumber",
});
```

✅ Works - `@type` completion (not part of function argument) from `@import` completion inside

```
///

// @allowJS: true
// @checkJs: true
// @module: esnext

// @filename: ./a.ts
////export interface ABC {}

// @filename: ./b.js
/////** @import * as t from "./a" */
/////** @type {t./**/} */

verify.completions({
marker: "",
includes: "ABC",
});
```

❌ Does not work - `@type` completion (in function argument) from `@import` (argument not named yet)
```
///

// @allowJS: true
// @checkJs: true
// @module: esnext

// @filename: ./a.ts
////export interface ABC {}

// @filename: ./b.js
/////** @import * as t from "./a" */
////function someFunc(/** @type {t./**/} */) {}

verify.completions({
marker: "",
includes: "ABC",
});
```

❌ Does not work - `@type` completion (in function argument) `@typedef` (argument not named yet)

```
///

// @allowJS: true
// @checkJs: true
// @module: esnext

// @filename: ./b.js
/////** @typedef {number} SomeNumber */
////function someFunc(/** @type {S/**/} */) {}

verify.completions({
marker: "",
includes: "SomeNumber",
});
```

### 🙁 Actual behavior

See above, completions are missing.

### 🙂 Expected behavior

See above, completions are present.

### Additional information about the issue

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the fourslash.ts reproductions in the issue, especially the virtual b.js cases using JSDoc @type inside a function argument. Trace TypeScript language-service completion handling for these JSDoc type expressions and compare it with the working @typedef and standalone cases. Done means regression coverage shows ABC and SomeNumber completions in the missing cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.