microsoft / microsoft/TypeScript

Comparison of different enumeration types error

Open
#56,524 0 comments 2 reactions 0 assignees View on GitHub

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
⭐ 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
Screenshot 2023-11-23 164017

Rust
_rust

💻 Use Cases
  1. What do you want to use this for?
    Comparison operations between non-overlapping enum types

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.