== Why is this an issue?

TypeScript provides enums to allow developers to define a set of named constants under a common type. These enum constants can be assigned values, but it is not mandatory to assign all of them. Those that are not assigned get default values in increasing order starting from zero. As a result, assigning only a subset of enum members can be misleading. For numeric enums in particular, that would create a gap in the numerical order, which could lead to unfortunate bugs. In addition, adding more members or moving around existing ones might change their values.

This rule raises an issue whenever an enum assigns a subset of its members, unless the first member only is assigned a numerical literal.

[source,typescript]
----
enum Key {
    Up = 1,
    Down,
    Left,
    Right
}
----

== How to fix it

Either assign a value to all enum members or none of them, or assign a number literal to the first enum member only.

=== Code examples

==== Noncompliant code example

[source,typescript,diff-id=1,diff-type=noncompliant]
----
enum Digit {
   Zero,
   One,
   ...
   Nine = 9
}
----

==== Compliant solution

[source,typescript,diff-id=1,diff-type=compliant]
----
enum Digit {
    Zero,
    One,
    ...
    Nine
}
----

==== Noncompliant code example

[source,typescript,diff-id=2,diff-type=noncompliant]
----
enum RGB {
   Red,
   Green,
   Blue = 0b000000000000000011111111
}
----

==== Compliant solution

[source,typescript,diff-id=2,diff-type=compliant]
----
enum RGB {
   Red   = 0b111111110000000000000000,
   Green = 0b000000001111111100000000,
   Blue  = 0b000000000000000011111111
}
----

//=== How does this work?

//=== Pitfalls

//=== Going the extra mile

== Resources

=== Documentation

* https://www.typescriptlang.org/docs/handbook/enums.html[TypeScript - Enums]

//=== Articles & blog posts
//=== Conference presentations
//=== Standards
