Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

ts enum

// String enum 
enum Direction {
  Up = "UP",
  Down = "DOWN",
  Left = "LEFT",
  Right = "RIGHT",
}

// Numeric enums
enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}
Comment

enum in ts

enum Direction {
    Up,
    Down,
    Left,
    Right,
}
Comment

typescript enum

enum Sides {LEFT, RIGHT};
Sides.LEFT;  // 0
Sides.RIGHT; // 1

const typeFromEnum: Sides.LEFT = Sides.LEFT; // Enums become types!

console.log(Sides);   // { '0': 'LEFT', '1': 'RIGHT', LEFT: 0, RIGHT: 1 } 

type leftOrRight = keyof typeof Sides; // 'LEFT' | 'RIGHT'

let sideName: string = Sides[0];  // 'LEFT'  reverse mapping


enum EnumWithString {
  X = "XX",
  Y = "YY",
};
console.log(EnumWithString); // { X: 'XX', Y: 'YY' }  no reverse mapping
Comment

TypeScript enum

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}
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.

If we wanted, we could leave off the initializers entirely:
enum Direction {
  Up,
  Down,
  Left,
  Right,
}
  
enum Direction {
  Up = "UP",
  Down = "DOWN",
  Left = "LEFT",
  Right = "RIGHT",
}
Comment

ts enum

enum vscode {
    good,bad,medium
}

console.log(vscode.bad)
Comment

ts enum

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}
Try
Comment

typescript enum

enum EMoney {
	gopay = 'gopay',
	dana = 'dana',
	ovo = 'ovo'
}

enum Bank {
	bca = 'bca',
	mandiri = 'mandiri',
	bri = 'bri'
}

interface OnlineShop<T> {
	payment: T
}

const payment: OnlineShop<Bank> = {
	payment: Bank.bca
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to pring events in pygame 
Typescript :: ts compile command 
Typescript :: onblur vs valuechange 
Typescript :: open ports for remote access on linux 
Typescript :: typescript cast string to number 
Typescript :: typescript delete value from map 
Typescript :: google places auto-complete 
Typescript :: removing directories in linux 
Typescript :: across tab localstorage 
Typescript :: slice string into segments of 2 characters 
Typescript :: google sheets k format 
Typescript :: A HTML5 fullscreen plugin for Leaflet. 
Typescript :: using method parameters in a guard nestjs 
Typescript :: Count by One Variable 
Typescript :: ts(2503) 
Typescript :: concat and nunll check in typescript 
Typescript :: file attachements contac form 7 
Typescript :: Carbohydrates and fats both 
Typescript :: react input onchange typescript 
Typescript :: typescript checkbox object is possibly null 
Typescript :: benefits of waxing body hair 
Typescript :: convert f# 
Typescript :: @ViewChild takes 2 arguments error 
Typescript :: delete the last string from file in typescript 
Typescript :: hhow to remove elements from java 
Typescript :: ts number addition is concatenating like strings 
Typescript :: ring Composition and Returning Objects and Lists by Reference 
Typescript :: How can I manage several subcontracting locations? 
Typescript :: react-stripe-elements hidePostalCode 
Typescript :: devide the subplot into subplots in mathplotlib 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =