Error Messages Related to Nested Identical Generic Names Could Be More Explicit

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

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

評価

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

調査の方向性

まず、issue のネストされたジェネリックの例を再現し、内側のジェネリックを T と名付けた場合に生成される診断と、外側の T を使用するバージョンで生成される診断を比較します。これらのエラーについて TypeScript の型チェッカーの診断パスを追跡し、実行時の出力を変更せずにネストされた同一のジェネリックラベルを区別できた時点で作業完了とします。

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

説明

Domain: Error Messages Experience Enhancement Needs Proposal Suggestion

Suggestion

🔍 Search Terms

identical generics
overlapping generics
nested generics

✅ Viability Checklist

My suggestion meets these guidelines (please notify me if my checklist is incorrect):

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Modify generic-related error messages, that involve 2 or more nested, identically named generic labels, to be more explicit.
e.g. Append "(which is a different type from the first 'T')" (or something similar) to the original message.

📃 Motivating Example

The following error message was caused by a function nested within a function using the same generic label (as well as some erroneous code.) I suggest we modify generic-related error messages where there are 2 or more nested generic labels that have the same name. A more explicit message would help nudge the developer towards the real error source.

image

Here is a snippet of the actual source code:

export function useForm<T extends FormFieldData>() {
  // ...
  function<T extends FormFieldData>(input: FormFieldKeys<T>) {
    // ...
  }
}

The solution in this case was removing the unnecessary nested generic and using the useForm scoped generic:

export function useForm<T extends FormFieldData>() {
  // ...
  function (input: FormFieldKeys<T>) {
    // ...
  }
}

@DanielRosenwasser @sandersn

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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