TypeScript: Handbook - Enums
typescriptlang.org · 2,430 words · saved by 1 readers
How TypeScript enums work
Enums are one of the few features TypeScript has which is not a type-level extension of JavaScript. Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums. Numeric enums We’ll first start off with numeric enums, which are probably more familiar if you’re coming from other languages. An enum can be defined using the enum keyword. ts enum Direction { Up = 1 , Down , Left , Right , } Try Above, we have a numeric enum where Up is initialized with 1 . Al
related reading
- Basic TypeScriptweb.mit.edu
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org
- TypeScript: Documentation - The Basicstypescriptlang.org
- Reading 2: Basic TypeScriptweb.mit.edu
- TypeScript: Documentation - TypeScript 3.7typescriptlang.org
- Shikishiki.style
- Everything is Fertilenickcammarata.com
- TypeScript: Documentation - TypeScript for the New Programmertypescriptlang.org
- Enums and Pattern Matching - The Rust Programming Languagedoc.rust-lang.org
- TypeScript: Documentation - Object Typestypescriptlang.org
- Reading 12: Defining ADTs with Interfaces, Generics, Enums, and Functionsweb.mit.edu
- TypeScript: Documentation - Classestypescriptlang.org