48 lines
970 B
Plaintext
48 lines
970 B
Plaintext
== Why is this an issue?
|
|
|
|
TypeScript allows assigning values to enum members. However, it does not enforce uniqueness between the values of such members. As a result, assigning the same value to different members is possible.
|
|
|
|
The rule raises issues on duplicate values because they are misleading and can lead to bugs that are hard to track down.
|
|
|
|
== How to fix it
|
|
|
|
Assign a unique value for each enum member or don't assign any values.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,typescript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
enum E {
|
|
X = 0,
|
|
Y = 0,
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,typescript,diff-id=1,diff-type=compliant]
|
|
----
|
|
enum E {
|
|
X = 0,
|
|
Y = 1,
|
|
}
|
|
----
|
|
|
|
//=== How does this work?
|
|
|
|
//=== Pitfalls
|
|
|
|
//=== Going the extra mile
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* TypeScript Documentation - https://www.typescriptlang.org/docs/handbook/enums.html[Enums]
|
|
|
|
//=== Articles & blog posts
|
|
//=== Conference presentations
|
|
//=== Standards
|