TypeScript Enum

Enumeration (Enum) is a data type in typescript. that are used to store constant element value. There is three type of Enum will possible in typescript.

Numeric Enum

enum Month{
  January,
  February,
  March,
  April,
  May,
  June
};
Default values of numeric Enum
enum Wallet{
  coins = 10,
  rupee = 100,
  dollar = 3,
  euro  = 12
};
Example Numeric Enumeration

String Enum

enum Month{
  Jan="January",
  Feb="February",
  Mar="March",
  Apr="April",
  May="May",
  June="June"
};
console.log(Month);
String Enumeration Example
{ Jan: 'January',
  Feb: 'February',
  Mar: 'March',
  Apr: 'April',
  May: 'May',
  June: 'June' }

Heterogeneous Enum

enum Code{
  error = 0,
  status,
  type  = "Typescript"
};
console.log(Code);
Heterogeneous Enumeration Example
{ '0': 'error',
  '1': 'status',
  error: 0,
  status: 1,
  type: 'Typescript' }


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved