Tutorial by Examples

enum SomeEnum { A, B } let enumValues:Array<string>= []; for(let value in SomeEnum) { if(typeof SomeEnum[value] === 'number') { enumValues.push(value); } } enumValues.forEach(v=> console.log(v)) //A //B
By default all enum values are resolved to numbers. Let's say if you have something like enum MimeType { JPEG, PNG, PDF } the real value behind e.g. MimeType.PDF will be 2. But some of the time it is important to have the enum resolve to a different type. E.g. you receive the value fr...
Sometimes it is required to implement Enum on your own. E.g. there is no clear way to extend other enums. Custom implementation allows this: class Enum { constructor(protected value: string) {} public toString() { return String(this.value); } public is(value: Enum | string) { ...
enum SourceEnum { value1 = <any>'value1', value2 = <any>'value2' } enum AdditionToSourceEnum { value3 = <any>'value3', value4 = <any>'value4' } // we need this type for TypeScript to resolve the types correctly type TestEnumType = SourceEnum | AdditionToS...

Page 1 of 1