Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: forbid using TypeScript enums using eslint
[TypeScript enums][1] are an unusual TypeScript feature, because it's one of the only features that is "not a type-level extension of JavaScript". This means TypeScript generates custom code for enums, which can cause a bunch of issues, especially as this custom code can be built differently depending on which bundler you use, and because of this, many people discourage the use of enums: - [The Dangers of TypeScript Enums][2] - [Tidy TypeScript: Prefer union types over enums][3] - [TypeScript: Handbook - Enums # Objects vs Enums][4] I've added an ESLint rule that forbids TypeScript enums, as in most cases, it's better to use string literals instead, e.g. like `type a = "a" | "b" | "c";`. [1]: https://www.typescriptlang.org/docs/handbook/enums.html#string-enums [2]: https://dev.to/azure/the-dangers-of-typescript-enums-55pd [3]: https://fettblog.eu/tidy-typescript-avoid-enums/ [4]: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
- Loading branch information