I have this function to flatten an object
export function flattenObject(object: Object, prefix: string = "") {
return Object.keys(object).reduce((messages, key) => {
const value: Object | string = object[key];
const prefixed = prefix ? `${prefix}.${key}` : key;
const flatMessages = { ...messages };
if (typeof value === "string") {
flatMessages[prefixed] = value;
} else {
Object.assign(flatMessages, flattenObject(value, prefixed));
}
return flatMessages;
}, {});
}
on line 3, there is this part object[key]
that says its uncovered
[flow coverage] uncovered code (parameter) object: Object [Flow] object: Object
I'm not entirely sure why, as it does say its an Object? Shape of the object can vary however, so my initial assumption is maybe its due to it being loosely defined? If so is there a workaround for the warning message?
I believe it is due to Flow expecting a better annotation to your object argument than Object
, you could try {}
for a quick win or create a type annotation (recommended) for it as described here.
E.g.
flattenObject(object: { foo: string }, prefix: string = "") { ...