microsoft / microsoft/TypeScript
Comparison of different enumeration types error
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔍 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the enum comparison examples from the issue in a TypeScript test case and compare the existing equality diagnostic with relational operators. The change is done when comparisons between distinct enum types consistently produce the intended type-check error without changing emitted JavaScript behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100