Flow allow concatenation with object.entries and string
Object.entries
is typed as:
static entries(object: $NotNullOrVoid): Array<[string, mixed]>
And when you try to use a value of a mixed
type you must first figure out what the actual type is or you’ll end up with an error, so you can use Flow's type refinement :
Object.entries(my).forEach(entry => {
if (typeof entry[1] === 'number') {
mystring = entry[1] + mystring;
}
});
You could also just cast entry[1]
:
Object.entries(my).forEach(entry => {
mystring = Number(entry[1]) + mystring;
});
or add type to entry
like this entry: [string, any]
but note that using any
is completely unsafe, and should be avoided whenever possible.
DEMO