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: docs/typescript.md
+33-6Lines changed: 33 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -974,14 +974,19 @@ The concept of the interface as discussed in this section is not to be confused
974
974
975
975
TypeScript offers several tools for crafting clear data definitions, with enumerations and unions standing as popular choices.
976
976
977
-
#### Consider using enums over union types for situations with a fixed set of known values.
977
+
> [!NOTE]
978
+
> `enum` syntax is being phased out of TypeScript. v5.8 introduces a new flag `erasableSyntaxOnly`, which will mark enums as errors (along with namespaces and class parameter properties).
979
+
>
980
+
> The recommended alternative is to use objects defined with the `asconst` keyword (see https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums).
981
+
982
+
#### Consider using `asconst` objects over union types when enumerating a fixed set of known values.
978
983
979
984
Inevitably you will want to refer to the values of a union type somewhere (perhaps as the argument to a function). You can of course just use a literal which represents a member of that union — but if you have an enum, then all of the values are special, and any time you use a value then anyone can see where that value comes from.
Therearetwowaysthatexplicitfunction return types can be useful. Fortunately there are
1029
1047
1030
-
Although TypeScript is capable of inferring return types, adding them explicitly makes it much easier for the reader to see the API from the code alone and prevents unexpected changes to the API from emerging.
1048
+
1049
+
1050
+
1.
1051
+
1052
+
Unfortunately, this comes at
1053
+
1054
+
artificially widen the return type
1055
+
1056
+
1057
+
makes it much easier for the reader to see the API from the code alone and prevents unexpected changes to the API from emerging.
0 commit comments