microsoft / microsoft/TypeScript

Suggestion: make hover tooltips more readable by showing the generic parameters names instead of their value (in some cases)..

オープン
#62,634 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

🔍 Search Terms

tooltip generic parameters
expandable hover
format hover

Related issues:

I searched for both open and close issues, didn't found a duplicate, maybe I didn't use the correct search terms.

✅ Viability Checklist
⭐ 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
function foo<T extends Record<string, any>>(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

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<T>.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.

  1. What shortcomings exist with current approaches?

Tooltip can be hard to read.

  1. 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた TypeScript Playground を使って動機となる例を再現し、報告されているホバーツールチップの出力を確認します。リポジトリのファイル、テスト、実装のエントリーポイントのいずれも指定されていないため、まずサイズのしきい値、展開の動作、想定されるジェネリックパラメーターの表示を明確にします。ホバー時の出力がより読みやすくなり、基になる型を調べるための適切な方法も維持されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。