Перейти к содержимому

useConsistentEnumValueType

Это содержимое пока не доступно на вашем языке.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentEnumValueType": "error"
}
}
}
}

Disallow enums from having both number and string members.

TypeScript enums are allowed to assign numeric or string values to their members. Most enums contain either all numbers or all strings, but in theory you can mix-and-match within the same enum. Mixing enum member types is generally considered confusing and a bad practice.

enum Status {
Unknown,
Closed = 1,
Open = 'open',
}
code-block.ts:3:3 lint/nursery/useConsistentEnumValueType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Inconsistent enum value type.

1 │ enum Status {
2 │ Unknown,
> 3 │ Closed = 1,
^^^^^^^^^^
4 │ Open = ‘open’,
5 │ }

Another inconsistent enum value type.

2 │ Unknown,
3 │ Closed = 1,
> 4 │ Open = ‘open’,
^^^^^^^^^^^^^
5 │ }
6 │

Mixing number and string enums can be confusing. Make sure to use a consistent value type within your enum.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

enum Status {
Unknown = 0,
Closed = 1,
Open = 2,
}
enum Status {
Unknown,
Closed,
Open,
}
enum Status {
Unknown = 'unknown',
Closed = 'closed',
Open = 'open',
}