跳到內容

typescript/prefer-enum-initializers 吹毛求疵

🚧 自動修正功能仍在開發中。

作用

要求每個 enum 成員的值都必須明確初始化。

為什麼這不好?

在 `enum` 成員的值很重要的專案中,允許 enum 的隱含值可能會在 enum 隨著時間修改時導致錯誤。

範例

typescript
// wrong, the value of `Close` is not constant
enum Status {
  Open = 1,
  Close,
}

參考資料

以 MIT 授權釋出。