Avoid duplicate enum member values
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。
ID: typescript-best-practices/no-duplicate-enum-values
Language: TypeScript
Severity: Warning
Category: Error Prone
Description
An enum
should not have duplicate values, which are usually not expected to be present.
Non-Compliant Code Examples
enum A {
A = 1,
B = 1,
}
enum B {
A = 'A',
B = 'A',
}
enum C {
A = 'A',
B = 'A',
C = 1,
D = 1,
}
enum E {
A = 'A',
B = 'A',
C = 1,
D = 1,
}
Compliant Code Examples
enum A {
A,
B,
}
enum B {
A = 1,
B,
}
enum C {
A = 1,
B = 2,
}
enum D {
A = 'A',
B = 'B',
}
enum E {
A = 'A',
B = 'B',
C,
}
enum F {
A = 'A',
B = 'B',
C = 2,
D = 1 + 1,
}
enum G {
A = 3,
B = 2,
C,
}
enum H {
A = 'A',
B = 'B',
C = 2,
D = foo(),
}
enum I {
A = '',
B = 0,
}
enum J {
A = 0,
B = -0,
C = NaN,
}
Seamless integrations. Try Datadog Code Analysis