docs(enums-vs-union-types): update docs content (const enums)

This commit is contained in:
Sven Brodny
2024-03-03 16:40:34 +01:00
parent 8ccb746c4c
commit 7918f4deb9

View File

@@ -33,7 +33,7 @@ Enums are a concept borrowed from languages like C# and Java. TypeScript Enums a
Enums have some more pitfalls as well: Enums have some more pitfalls as well:
- Non-const enums do not fit to the concept "a typed superset of JavaScript". They violate the concept by emitting JavaScript objects that live in runtime with a syntax that is not compatible with JavaScript. - Non-const enums do not fit to the concept "a typed superset of JavaScript". They violate the concept by emitting JavaScript objects that live in runtime with a syntax that is not compatible with JavaScript.
- Const enums in contrast cannot be transpiled with Babel. But there are workarounds for this issue, e. g. using `babel-plugin-const-enum` plugin. - Const enums in contrast cannot be transpiled with Babel. But there are workarounds for this issue, e. g. using `babel-plugin-const-enum` plugin. The TypeScript documentation about [const enums](https://www.typescriptlang.org/docs/handbook/enums.html#const-enums) says "_Do not use const enums at all_".
- To use enums you have to import them, if you want to use enum values in a template, you'll need to declare a variable in your component too. - To use enums you have to import them, if you want to use enum values in a template, you'll need to declare a variable in your component too.
- Numeric enums are not type safe ... - Numeric enums are not type safe ...