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

enum usage typescript

enum UserResponse {
  No = 0,
  Yes = 1,
}

function respond(recipient: string, message: UserResponse): void {
  console.log(recipient, message); // "Princess Caroline",  1
}

respond("Princess Caroline", UserResponse.Yes);
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 :: why in angular template i cant use Object.Keys() 
Typescript :: laravel many to many get related posts by category 
Typescript :: useformik type for typescript 
Typescript :: typescript loop through dictionary 
Typescript :: wordpress number of posts by user 
Typescript :: replace element in array typescript 
Typescript :: make foreign key sql in exists row 
Typescript :: Create Hash Node TypeScript 
Typescript :: typescript generic object 
Typescript :: rails precompile assets in a directory 
Typescript :: mongodb update all items in array 
Typescript :: typescript combine interfaces 
Typescript :: call function dynamically typescript 
Typescript :: computed vue typescript 
Typescript :: angular link local library 
Typescript :: array in typescript 
Typescript :: execute script when c# code gets executed 
Typescript :: cra ts pwa 
Typescript :: multi select 
Typescript :: coldfusion arrayLast 
Typescript :: persists meaning 
Typescript :: Two sets of parentheses after function call 
Typescript :: promise.all inside useEffect 
Typescript :: Unshift type Typescript 
Typescript :: use pipe in ts file angulr 
Typescript :: What kind of projects is suitable for the Agile methodology 
Typescript :: grid implementation html canvas 
Typescript :: how to show code conflicts in git 
Typescript :: java login attempts using for loop 
Typescript :: using method parameters in a guard nestjs 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =