Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set enum to range of number in typeorm

I want to create an enum with a range of numbers from 1 to 200.

There are too many to list all of them one by one, so I want to use a function like range.


export enum NumberData {
  // ???
}

In the code above ???,
Please tell me what code to put inside.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Probably, is not possible. Because enums in TypeScript translates to function in javascript (not arrays). You can’t automatically fill fields inside a function. You can fill only arrays

enum NumberData {
    ONE = 1,
    TWO = 2
}
// translates to =>
"use strict";
var NumberData;
(function (NumberData) {
    NumberData[NumberData["ONE"] = 1] = "ONE";
    NumberData[NumberData["TWO"] = 2] = "TWO";
})(NumberData || (NumberData = {})); 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading