Skip to content

Add additional type overload to Object.values #30870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

keriwarr
Copy link

  • There is an associated issue that is labeled 'Bug' or 'help wanted'
  • Code is up-to-date with the master branch
  • You've successfully run gulp runtests locally
  • There are new or updated unit tests validating the change

I'm making this PR on github, gonna check out the project and run gulp/tests as soon as I open it

Motivation

I use a lot of enums, and I am very frequently writing code which exhuastively switches over enums, and so on. Fairly often I find that I want to check whether a value is contained within an enum, or iterate over the values in the enum.

The way I've been doing that is like this:

enum Foo {
  A,
  B,
}

if ((Object.values(Foo) as Foo[]).includes(value) {
  ...
}

with this new overload, I can more simply do

if (Object.values(Foo).includes(value) {
  ...
}

As far as I can tell, this new overload doesn't interfere with standard uses of Object.values

Tests

still working on it. opening as draft for now

@RyanCavanaugh
Copy link
Member

Recommend reading #26901; we would not accept this PR

@keriwarr keriwarr closed this Apr 12, 2019
@keriwarr keriwarr deleted the patch-1 branch April 12, 2019 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants