Note the read-only definition is only shown when we hover the mouse over the directionEnum const: const directionEnum: Readonly ![]() ![]() We can use this construct as shown in the example below: const directionEnum = eeze(ĭoing this, we get an object that is read-only and protected. They also allow us to specify a list of values for a particular collection set or type.Įnums are not natively supported in JavaScript, but there is a workaround that lets us replicate their behavior in the language using the eeze construct, since TypeScript treats enums as if they were real objects (although applicable for non-const enums at runtime). The enums keyword offers a way for us to define a finite set of values - usually as named constants in a strongly typed way. If you are new to the JavaScript/TypeScript landscape, you might be wondering what Enums are. In this section, we are going to explore string enums in TypeScript. Octo10 min read 2872 An intro to string-based enums TypeScript string enums, and when and how to use them React, Node.js, Python, and other developer tools and libraries. ![]() Alexander Nnakwue Follow Software engineer.
0 Comments
Leave a Reply. |