When working with Typescript, I am looking to retrieve all values of an enum
type and store them in an array. In C#, a similar method would look like this:
public static TEnum[] GetValues<TEnum>() where TEnum : Enum
{
return Enum.GetValues(typeof(TEnum))
.OfType<TEnum>()
.ToArray();
}
How can we achieve the same functionality in Typescript? Ideally, the usage would resemble:
const allColors: Color[] = GetEnumValues<Color>();
Just for reference, I am using Typescript version 3.9.4 but open to suggestions for newer versions.