Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 255
    This doesn't work with --noImplicitAny (in VS unchecked "Allow implicit 'any' types"). It produces error TS7017: Index signature of object type implicitly has an 'any' type. For me this worked: var color: Color = (<any>Color)[green]; (tested with version 1.4) Commented Mar 13, 2015 at 19:31
  • 3
    @Vojta said right. Its not working in VS 2012. This one worked but var color: Color = (<any>Color)[green]; Commented Sep 29, 2015 at 10:02
  • 1
    Note that this won't work if the enum is defined as "const" Commented Oct 3, 2017 at 21:27
  • 3
    It doesn't work here either, the official documentation seems to confirm that: typescriptlang.org/docs/handbook/release-notes/… Commented Nov 25, 2017 at 15:11
  • 236
    Make sure to use this if --noImplicitAny var color : Color = Color[green as keyof typeof Color]; Commented May 10, 2019 at 10:48