I'm trying to get all items of a TypeScript Enumeration. For this I use the following, generic function:
static getAllValues<T>(enumeration: T): Array<T>{
let enumKeys: Array<T> = Object.keys(enumeration).map(k => enumeration[k]);
let items: Array<T> = new Array<T>();
for(let elem of enumKeys){
if (typeof(elem) === "number"){
items.push(elem)
}
}
return items;
}
By calling this function with an Enum of the Type ExampleEnum like
export enum ExampleEnum {
FOO,
BAR,
FOOBAR
}
I expected a return value from the type Array<ExampleEnum> but the response is from the type Array<typeof ExampleEnum>.
Does anyone know how to fix it, to get a return from the type Array<ExampleEnum>?
(I'm using TypeScript 3.2.1)