microsoft / microsoft/TypeScript
Suggestion: make hover tooltips more readable by showing the generic parameters names instead of their value (in some cases)..
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔍 Search Terms
tooltip generic parameters
expandable hover
format hover
Related issues:
- https://github.com/microsoft/TypeScript/issues/59029
I searched for both open and close issues, didn't found a duplicate, maybe I didn't use the correct search terms.
### ✅ 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
For readability sake, when displaying type info in the hover tooltip, it is better (in some cases) to show the generic parameters' names instead of their value.
The rule could be that when a generic type parameter exceed a certain size, to show its name instead of its value (with the possibility to expand it).
### 📃 Motivating Example
```ts
function foo>(o: T) {
return class X {
constructor(a: number, b: string) {}
}
}
const X = foo({
f1: 34, f2: 34, f3: 34, f4: 34, f5: 34, f6: 34, f7: 34, f8: 34, f9: 34, f10: 34,
});
new X(12, "ok")
```
[Playground Link](https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMOcA8AVRBTAHlbMAEwGdEAlbCOAJyLRKhpjAHMAaRAQzAE8A+fgAo4ALkQYAlIgDeAKESLENbFBA0kEADZcSZABqyFSk9TCMaIaLSFdxYEAFsARthqdn4iy1bSZAX2NFQMC5M0ZEQwBeZFQheRNgAEZxAGYAFk5gACY0zORUvKz0ouQAVlLgADZKgHZKgA5KgE5KpIAGIrl-SQBuOTkwbAB3SKEk7PYAIjgAayn2SSA)
When editing `new X()` arguments, the following tooltip is showing:
```
X(a: number, b: string): foo<{ f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }>.X
```
This can quickly become hard to read if the generic parameters are complex. The following would be easier to read (while keeping the ability to expand it*).
```
X(a: number, b: string): foo.X
```
_*Well, maybe expansion is not always the solution, and instead of showing the full type definition, to be able to browse the type, e.g. clicking on "T" to show its value (in another hover or by expanding it). Could be more appropriate when we want more precision on one part of the type, not on the whole type.
*Note: TS Playground doesn't seem to have the expandable hover tooltip feature._
### 💻 Use Cases
1. What do you want to use this for?
Improve hover tooltip readability.
2. What shortcomings exist with current approaches?
Tooltip can be hard to read.
3. What workarounds are you using in the meantime?
Some VSCode extensions, enable to "prettify" hover tooltips to some extends (e.g. MylesMurphy.prettify-ts).
The alternative would be to format the output to improve readability:
```
X(
a: number,
b: string
): foo<
{ f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }
>.X
```
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用链接的 TypeScript Playground 重现这个动机示例,并检查报告中的悬停工具提示输出。没有指定任何仓库文件、测试或实现入口,因此首先需要明确大小阈值、展开行为以及预期的泛型参数显示方式。完成的标准是悬停输出更易读,同时保留适当的方式来检查底层类型。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- developer-experience, tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100