microsoft / microsoft/TypeScript

Support `@import` JSDoc tag for auto-imports

未关闭
#62,008 3 条评论 13 个 reaction 已指派 0 人 在 GitHub 查看
Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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

贡献指南

打开贡献指南

调研方向

首先阅读此处描述的 TypeScript Language Server 行为,以及 issues #57207 和 #22160 中的上下文。跟踪 auto-imports 当前如何生成 inline JSDoc imports,然后确定受支持的结果应当是配置选项还是单独的操作;当 auto-imports 能够生成所请求的 @import 语法时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
developer-experience, tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。