Skip to content
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

Object.entries breaks the return type in a functional loop (map) #6376

Closed
dmatteo opened this issue May 30, 2018 · 2 comments
Closed

Object.entries breaks the return type in a functional loop (map) #6376

dmatteo opened this issue May 30, 2018 · 2 comments

Comments

@dmatteo
Copy link

dmatteo commented May 30, 2018

Looping over an array generated from an object literal, breaks the return type when using Object.entries, but works just fine when using Object.keys and then returning obj[key].

Offending code (also reproduced on Try Flow)

/* @flow */

type Value = {
  num: number,
  str: string,
}

const getValues = (): { [string]: Value } => ({
  key1: {
    num: 999,
    str: 'hello',
  },
  key2: {
    num: 42,
    str: 'what is my purpose?',
  },
});

// This works
const values: Value[] = Object.keys(getValues())
  .map(key => getValues()[key]);

// This doesn't
const values2: Value[] = Object.entries(getValues())
	.map(([key, value]) => value)

There might be some nuances I don't get on why this brakes, but it seems to me that they should behave in the same way (they definitely return the same data).

Thanks a bunch!

@wchargin
Copy link
Contributor

This is known. See comments and linked-to issues on #5663.

(I’d also love to see this changed, but I don’t think that there is any
new information in this issue.)

@mrkev
Copy link
Contributor

mrkev commented Jun 4, 2018

Closing in favor of #5663

@mrkev mrkev closed this as completed Jun 4, 2018
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

No branches or pull requests

3 participants