Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Conversation

@styfle
Copy link
Contributor

@styfle styfle commented Feb 12, 2019

I always forget this syntax.

Please add it to the handbook.

Fixes microsoft/TypeScript#14106

I always forget this syntax.

Please add it to the handbook.

Here's the original issue I found for reference: microsoft/TypeScript#14106
@tjallingt
Copy link

Should probably include a note that this doesn't work for enums with custom values:

enum LogLevel {
  ERROR = 'error',
  WARN = 'warn',
  INFO = 'info',
  DEBUG = 'debug',
}

since the type LogLevelStrings will be 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' instead of 'error' | 'warn' | 'info' | 'debug'

This better describes what is happening with enums
@styfle
Copy link
Contributor Author

styfle commented Feb 12, 2019

@tjallingt It works for string enums too. I reworded the description to be clear that this is getting the keys and not the values.

See this example and try running the JS output.

@tjallingt
Copy link

Great! I find the updated text much clearer 👍
And yea i meant to say that the way it works is a little bit less clear when concerning enums with custom values. (Yea it says keyof but it doesn't hurt being explicit about what part is actually the key ;p)

@orta
Copy link
Contributor

orta commented Jun 26, 2019

Cool, thanks!

@orta orta merged commit de3223c into microsoft:master Jun 26, 2019
@styfle styfle deleted the patch-4 branch June 26, 2019 02:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

keyof Enum

4 participants