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

Objects with indexer properties lose type information after object spread #6871

Open
swac opened this Issue Sep 9, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@swac

swac commented Sep 9, 2018

Flow seems to think the result of an object spread on a map object is just Object, rather than the original type. This makes it hard to safely merge multiple map objects into one.

/* @flow */

type A = { [string]: number };

const foo: A = { a: 5 };

foo.b = '5'; // Error, as expected.

const bar = { ...foo };

bar.b = '5'; // No error, despite not matching A's definition.

See https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgCCYAvGAN5gDaAzhgE4CWAdgOYC6AXGMwK4C2AIzz0wAXwDc6AMZxmdMFDhxuxMpQCG3AKzipqJXAB0g0mADk28xLDBgYAKL16cegBowGmmDwAPfNIYeAAmRjJyCoIaoupgRvGGeuhR9CZmlta29gBycD7Orh7BeDQ4jEE8cBhg-BoY0gAWLKxE5t7FUCzljHJGQA.

I think this may be a distinct issue from #6505, since this one deals with map objects rather than exact objects.

@wchargin

This comment has been minimized.

Show comment
Hide comment
@wchargin

wchargin Sep 11, 2018

Contributor

Agreed that this a bug, and different from #6505.

These are called objects with indexer properties (commenting with this
keyword to improve searchability). A “Map object” may quite reasonably
be interpreted as an instance of Map.

Contributor

wchargin commented Sep 11, 2018

Agreed that this a bug, and different from #6505.

These are called objects with indexer properties (commenting with this
keyword to improve searchability). A “Map object” may quite reasonably
be interpreted as an instance of Map.

@swac swac changed the title from Map objects lose type information after object spread to Objects with indexer properties lose type information after object spread Sep 11, 2018

@swac

This comment has been minimized.

Show comment
Hide comment
@swac

swac Sep 11, 2018

@wchargin good point, I've updated the title of this issue to be more precise.

swac commented Sep 11, 2018

@wchargin good point, I've updated the title of this issue to be more precise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment