Typescript 的枚举类型是对 JavaScript 标准数据类型的扩展对于熟悉C语言的开发者来说,枚举类型并不陌生,它是一系列数值集合,我们可以更很方便维护一组数据集。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
enum Direction { Up = 1, Down, Left, Right } console.log(Direction.Down)
enum Direction { Up = 'Up', Down = 'Down', Left = 'Left', Right = 'RIGHT', }
const value = 'Up' if(value===Direction.Up){ console.log('go Up!') }
var Direction;
(function (Direction) { Direction["Up"] = "Up"; Direction["Down"] = "Down"; Direction["Left"] = "Left"; Direction["Right"] = "RIGHT"; })(Direction || (Direction = {}));
var value = 'Up';
if (value === Direction.Up) console.log('go Up!');
const enum Direction { Up = 'Up', Down = 'Down', Left = 'Left', Right = 'RIGHT', }
const value = 'Up'
if(value===Direction.Up){ console.log('go Up!') }
var value = 'Up';
if (value === "Up" ) { console.log('go Up!'); }
|