Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript type from enum values

enum Weekday {
  MONDAY = 'mon',
  TUESDAY = 'tue',
  WEDNESDAY = 'wed'
}

type WeekdayType = `${Weekday}`;
Comment

typescript value in enum

export enum MESSAGE_TYPE {
    INFO = 1,
    SUCCESS = 2,
    WARNING = 3,
    ERROR = 4,
};

var type = 3;

if (type in MESSAGE_TYPE) {

}
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

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

typescript enum value to enum

enum Number {
  One,
  Two
}  

const numberOne: Number = "One" as Number;
const otherNumberOne: Number = Number.One;

const stringOne = Number[Number.One];
Comment

PREVIOUS NEXT
Code Example
Typescript :: angular footer at bottom of page 
Typescript :: typescript window ethereum 
Typescript :: how to send data between components in react with redirect 
Typescript :: react protected routes typescript 
Typescript :: How to do Email validation using Regular expression in Typescript 
Typescript :: media breakpoints bootstrap 4 
Typescript :: drop table if exists redshift 
Typescript :: There can only be one default row without a when predicate function. 
Typescript :: list of environment python 
Typescript :: angular closest element 
Typescript :: vscode collapse all 
Typescript :: angular output send click event to parent 
Typescript :: how to use variables with if statements python 
Typescript :: create react project in typescript 
Typescript :: godot preload 
Typescript :: pathmatch angular 
Typescript :: ts console.log 
Typescript :: how to separate elements in list python 
Typescript :: useselector typescript 
Typescript :: How to Solve Property ‘getContext’ does not exist on type ‘HTMLElement’ error in Angular 12 & TypeScript 
Typescript :: check if drive exists c# 
Typescript :: get elements in list in another list c# 
Typescript :: git check if its up to date 
Typescript :: how to link custom fonts in react native 
Typescript :: how to make a button that alerts when clicked with html 
Typescript :: how can i take multiple inputs from the user in discord.js 
Typescript :: state in react typescript 
Typescript :: how to sort a list of lists in python 
Typescript :: what is test data 
Typescript :: string of bits to integer java 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =