microsoft / microsoft/TypeScript

Support `@import` JSDoc tag for auto-imports

Aperta
#62,008 3 commenti 13 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

### 🔍 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.)_

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo il comportamento di TypeScript Language Server descritto qui e il contesto nelle issue #57207 e #22160. Traccia il modo in cui auto-imports producono attualmente import JSDoc inline, quindi determina se il risultato supportato debba essere un'opzione di configurazione o un'azione separata; il lavoro è completato quando auto-imports possono produrre la sintassi @import richiesta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
developer-experience, tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.