noEnum
¥Summary
-
规则生效日期:
v1.9.0¥Rule available since:
v1.9.0 -
诊断类别:
lint/style/noEnum¥Diagnostic Category:
lint/style/noEnum -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
¥How to configure
{ "linter": { "rules": { "style": { "noEnum": "error" } } }}¥Description
禁止 TypeScript 枚举。
¥Disallow TypeScript enum.
TypeScript 枚举不是 JavaScript 的类型级扩展,如类型注释或定义。用户可能希望禁用非类型级扩展以使用仅剥离类型的打包器或编译器。
¥TypeScript enums are not a type-level extension to JavaScript like type annotations or definitions. Users may wish to disable non-type-level extensions to use bundlers or compilers that only strip types.
此规则不涵盖常量枚举,因为 noConstEnum 已经处理它们。环境上下文中的枚举(包括声明文件)也将被忽略。
¥Const enums are not covered by this rule since noConstEnum already handles them.
Enums within the ambient context, including declaration files, are ignores as well.
¥Examples
¥Invalid
enum Foo { BAR = 'bar', BAZ = 'baz',}code-block.ts:1:1 lint/style/noEnum ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Don’t use enum
> 1 │ enum Foo {
│ ^^^^^^^^^^
> 2 │ BAR = ‘bar’,
> 3 │ BAZ = ‘baz’,
> 4 │ }
│ ^
5 │
ℹ TypeScript enums are not a type-level extension to JavaScript like type annotations or definitions. Users may wish to disable non-type-level extensions to use bundlers or compilers that only strip types.
ℹ Use JavaScript objects or TypeScript unions instead.
¥Valid
const Foo = { BAR: 'bar', BAZ: 'baz',} as consttype Foo = 'bar' | 'baz'const enum Foo { BAR = 'bar', BAZ = 'baz',}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号