You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,26 +8,28 @@ From [TypeScript Handbook on Enums](https://www.typescriptlang.org/docs/handbook
8
8
9
9
> Enums are one of the few features TypeScript has which is not a type-level extension of JavaScript.
10
10
11
-
In other words, TypeScript enums have their corresponsing runtime representations, they are not erased from your emitted JavaScript files after being compiled. This conflicts with one of the non-goals of [TypeScript Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals):
11
+
In other words, TypeScript enums have their corresponsing runtime representations, they are not erased from your emitted JavaScript files after being compiled. This conflicts with one of the [TypeScript Design Non-goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals#non-goals):
12
12
13
13
> Provide additional runtime functionality or libraries. Instead, use TypeScript to describe existing libraries.
14
14
15
15
Having this TypeScript feature extending into your compiled JavaScript also conflicts with the TypeScript slogan of being a **typed superset of JavaScript**, which further introduces vendor lock-in.
16
16
17
-
[Orta Therox](https://github.com/orta) from Typescript team mentioned in [one of his YouTube video](https://youtu.be/8qm49TyMUPI?t=1240) that the TypeScript team actually regrets some of the changes it made in the beginning, including introducing enums which basically add features to JavaScript.
17
+
[Orta Therox](https://github.com/orta) from Typescript team mentioned in one of his [YouTube video](https://www.youtube.com/watch?v=8qm49TyMUPI&t=1240) that the TypeScript team actually regrets some of the changes it made in the beginning, including introducing enums which basically add features to JavaScript.
18
18
19
-
Moreover, using enums in TypeScript has a lot of caveats and edge cases to keep in mind. Some aspects of it are even considered not **type safe**!!! Head over to these wonderful articles for more details on these issues:
19
+
Moreover, using enums in TypeScript has a lot of caveats and edge cases to keep in mind. Some aspects of it are even considered **not type safe**!!! Head over to these wonderful articles for more details on these issues:
Additionally, if you have been using [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript.html), you might already notice that one of the caveats is to avoid using `const enum`s, as those require type information to compile.
24
+
Additionally, if you have been using [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript.html), you might already notice that one of the [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript.html#caveats) is to avoid using `const enum`s, as those require type information to compile.
25
25
26
26
Nonetheless, TypeScript is still a very fantastic and powerful programming language that I love very much. Enums may have been a very good feature to have back in the early days (2011) when good alternatives did not yet exist.
27
27
28
-
However, we now already have alternatives better than enums, such as **const assertions** and **string unions**. Which is why I created this ESLint plugin to provide you with some configs and rules to disallow the use of TypeScript enums.
28
+
However, we now already have alternatives better than enums, such as **const assertions**, **string unions**, **discriminated union**, etc. Which is why I created this ESLint plugin to provide you with some handy configs and rules to disallow the use of TypeScript enums.
29
29
30
-
This article provides a very in-depth exploration on the alternatives to TypeScript enums: https://2ality.com/2020/02/enum-alternatives-typescript.html
30
+
This article provides a very in-depth exploration on the alternatives to TypeScript enums:
0 commit comments