I'm playing the hole day with keyof, typeof,... Is it possible to have one "source of data" for the enums and array?
for example:
- I want to have a enum type
- and an array
but I want to define one source of truth. At the moment I define 'limited','low','medium','high' 3 times and I have a lot of such "data-classes"
const myArray: string[] = [
'limited',
'low',
'medium',
'high'
];
type MyStringEnumType =
'limited'
| 'low'
| 'medium'
| 'high';
enum MyEnum
{
Limited = 'limited',
Low = 'low',
Medium = 'medium',
High = 'high'
}
type Both = MyStringEnumType | MyEnum;
let testVar1: Both = MyEnum.Limited; // works
let testVar2: Both = 'limited'; // works
console.log(myArray[0], myArray.length); // works
Thanks!
Greetings crazyx13th