Recent changes to indexer properties in spreads are causing pain
Proposal
I use the following pattern a lot in my code to combine old data with fresh new data
type Data = {
[key: string]: number,
}
const oldData: Data = {
"1": 100,
"4": 200,
}
const newData: Data = {
"1": 110,
"3": 160,
}
const combinedData: Data = {
...oldData,
...newData
}
This code now gives the error
Cannot determine a type for object literal [1]. `Data` [2] cannot be spread because the indexer string [3] may overwrite properties with explicit keys in a way that Flow cannot track. Can you spread `Data` [2] first or remove the indexer?
Since all the objects have no explicit properties (they all use indexers), then the error flow gives off makes no sense. As far as i can see, there is no way to use this pattern without littering my code with $FlowFixMe's.
Flow should understand that since there are no explicit properties to overwrite, and every property is of the same type, then therefore multiple object spreads shouldn't cause an error.
Use case
https://flow.org/try/#0C4TwDgpgBAIghsOUC8UDeAoKUDaBrCEALigGdgAnASwDsBzAXRJoFcBbAIwgoBpt+B2DAF8MGAMYB7GuSiSANgBN4iEiqSpM2AEQBGbSV0AGIzyxRtAFgNQATCbOiJ02TQgB3dWoQb05vTa6xmY6AMyBAGymImJSMsBQUpy0EMo+3ogoftgAdHkKaYghUHk5bp4+IkA
As far as i can see, there is no way to use this pattern without littering my code with $FlowFixMe's.
I agree this sure looks like a bug, and I hope someone on the Flow team sees it and fixes it. I think it should be possible to do better than this for a workaround, though.
The strategy I'd recommend is to concentrate the fixmes in a small number of helper functions. For example:
const combineData = (old: Data, new: Data): Data => ({
...old, ...new,
}: $FlowFixMe);
Depending on how you use this pattern in your actual code, you might have several functions along this line, or you might make a more generic version, or a combination.
Separately, you might edit the title of this issue to be more specific to the particular problem you're seeing. That'll be helpful for any reader, and there's a possibility it will make it more likely that a member of the Flow team notices the report and looks into it.
This works in the latest version of Flow (look at your Try Flow link again)