I would like a function that get values from an object, but flow complains when I try to export it. I cannot figure out how to write the right annotations.
type RowType = {|foo:string|};
type ListType = {[id:string]:RowType};
const objList: ListType = {
someId:{foo:"someValue"}
}
const values1 = (obj) => {
return Object.keys(obj).map(key => obj[key]);
}
values1(objList).forEach((row) => {
row.foo; //work as expected
row.bar; //raise an error as expected
});
export const values2 = (obj) => {
//Missing type annotation for `obj`
return Object.keys(obj).map(key => obj[key]);
//Missing type annotation for `U`. `U` is a type parameter declared in function type [1]
// and was implicitly instantiated at call of method `map` [2].
}
values2(objList).forEach((row) => {
row.foo; //expect to work
row.bar; //expect to raise an error
});
Find how to fix it