microsoft / microsoft/TypeScript
Comparison of different enumeration types error
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔍 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Vergleichsbeispiele für enum aus dem Issue in einem TypeScript-Testfall nachzustellen, und vergleiche die vorhandene Gleichheitsdiagnose mit relationalen Operatoren. Die Änderung ist abgeschlossen, wenn Vergleiche zwischen unterschiedlichen enum-Typen konsistent den beabsichtigten Typprüfungsfehler erzeugen, ohne das ausgegebene JavaScript-Verhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100