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

未關閉
#42,423 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
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 小時
30 天內合併 PR
117

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。