“Enum maszynopisu” Kod odpowiedzi

.env TypeScript

npm install dotenv;
 OR 
yarn add dotenv;


import * as dotenv from 'dotenv';

//inside your starter code, do this
...
...
dotenv.config();
...
DevPedrada

TypeScript enum to tablic

// Helper
const StringIsNumber = value => isNaN(Number(value)) === false;

// Turn enum into array
function ToArray(enumme) {
    return Object.keys(enumme)
        .filter(StringIsNumber)
        .map(key => enumme[key]);
}
Knerbel

Typincript Typ z wartości enum

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

type WeekdayType = `${Weekday}`;
Lively Lark

Enum maszynopisu

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
Naughty Nightingale

Enum maszynopisu

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
}
Restu Wahyu Saputra

Enum maszynopisu

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",
}
Faris Abuali

Odpowiedzi podobne do “Enum maszynopisu”

Pytania podobne do “Enum maszynopisu”

Więcej pokrewnych odpowiedzi na “Enum maszynopisu” w TypeScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu