Skip to content

Instantly share code, notes, and snippets.

View joshgrift's full-sized avatar

Josh Grift joshgrift

  • Canada
View GitHub Profile
@joshgrift
joshgrift / iterate_enums.ts
Created December 29, 2021 15:29
Iterate Over Typescript Enums
// Credit due: https://github.com/microsoft/TypeScript/issues/4753#issuecomment-694557208
function enumValues<T extends string>(enumObj: {
[key: string]: T;
}): IterableIterator<T>;
function enumValues<T extends string | number>(enumObj: {
[key: string]: T;
}): IterableIterator<Exclude<T, string>>;
function* enumValues<T>(enumObj: { [key: string]: T }): IterableIterator<T> {
let isStringEnum = true;