TypeScript enum
This is how the comment reads inline, under the flagged line.
Why it matters
Enums generate objects, number enums accept any number, and they don't work with type-stripping runtimes.
What to do
Use a union of string literals, or an as const object.
Examples
export enum Status { Open, Closed }export type Status = "open" | "closed";
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
export enum Status {
Open,
}Left alone
export const STATUSES = ['a', 'b'] as const;
Research
New TypeScript `enum`. Enums are not plain JavaScript, and numeric enums accept any number.
- skill: code-review
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"ts-enum"
],
"severity": {
"ts-enum": "medium"
}
}
}
enum. It emits runtime code and doesn't behave like the rest of the type system.