microsoft / microsoft/TypeScript
Comparison of different enumeration types error
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔍 Search Terms
"enums", "enum comparison"
✅ Viability Checklist
- 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 isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Show type-check error on different enumeration types comparing
📃 Motivating Example
enum Month {
Jan, Feb, Mar, Apr, May, Jun,
Jul, Aug, Sep, Oct, Nov, Dec
}
enum Week { Mon, Tue, Wed, Thu, Fri, Sat, Sun }
console.log('Month vs Month', Month.May > Month.Nov) // false
console.log('Week vs Week', Week.Wed > Week.Mon) // true
console.log('Equals', Week.Sun === Month.Nov) // false (type-check error)
console.log('Week vs Month', Week.Sun > Month.Nov) // false (expected type-check error?)
Comparing the equality of different enums results a type-check error:
This comparison appears to be unintentional because the types 'Week' and 'Month' have no overlap. (2367)
But no error on >, < or >=, <=
Error examples:
C
Rust
💻 Use Cases
- What do you want to use this for?
Comparison operations between non-overlapping enum types
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue にある enum の比較例を TypeScript のテストケースで再現し、既存の等価性診断を関係演算子と比較します。異なる enum 型間の比較が、出力される JavaScript の動作を変更せずに、意図した型チェックエラーを一貫して生成するようになれば、変更は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100