microsoft / microsoft/TypeScript

Support `@import` JSDoc tag for auto-imports

Open
#62,008 3 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔍 Search Terms

"jsdoc @import", "@import auto-import", "jsdoc auto-import"

### ✅ Viability Checklist

- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

### ⭐ Suggestion

Since #57207 it is possible to use the JSDoc `@import` tag.

```js
/** @import { Foo } from 'foo.js'; */

/** @type {Foo} */
const foo = ...;
```

However, auto-imports still only use the old inline syntax:

```js
/** @type {import('foo.js').Foo} */
const foo = ...;
```

It would be nice to also have the option to chose the new `@import` syntax for the auto-imports, either by configuring an option somewhere or simply by adding another action that can be exposed in IDEs.

### 📃 Motivating Example

I believe this falls in line with the ergonomics goals outlined by the original issue about having a nicer syntax for JSDoc imports #22160.

I will not repeat the arguments made therein, but suffice to say that it produces more readable code.

### 💻 Use Cases

Having the auto-import work with this syntax would:

* Save time, not having to write import statements by hand.
* Avoid mistakes due to typos, etc.
* Help people adopt the existing feature.

---

_(I have opened the issue here instead of over in [vscode](https://github.com/microsoft/vscode). Based on my understanding, this behavior is exposed by the TypeScript Language Server and not by the individual IDEs. Please correct me if I'm wrong.)_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the TypeScript Language Server behavior described here and the context in issues #57207 and #22160. Trace how auto-imports currently produce inline JSDoc imports, then determine whether the supported result should be a configuration option or a separate action; done means auto-imports can produce the requested @import syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.