Skip to content

Instantly share code, notes, and snippets.

@williscool
Created November 22, 2017 06:01
Show Gist options
  • Select an option

  • Save williscool/39ad5473524fab34bbb4d43e7e9e8c11 to your computer and use it in GitHub Desktop.

Select an option

Save williscool/39ad5473524fab34bbb4d43e7e9e8c11 to your computer and use it in GitHub Desktop.

Revisions

  1. williscool created this gist Nov 22, 2017.
    13 changes: 13 additions & 0 deletions filterEnum.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    /**
    * Filters am emum to only return the keys represented in it
    *
    * How is this not built into the language?
    * https://stackoverflow.com/a/21294925/511710
    * https://noahbass.com/posts/typescript-enum-iteration
    *
    * @param {{}} e
    * @returns
    */
    function filterEnum(e: {}) {
    return Object.keys(e).filter(v => isNaN(Number(v)));
    }