I have a type like this:
type Cool = {
[key: string]: number
}
Now, let's say I have an object with that type:
let my: Cool = {
"asdf": 1,
"jkl": 2
}
When I run Object.entries(my), I get [["asdf", 1], ["jkl", 2]]. This seems normal. However, I want to combine each key to form a string, like this:
let mystring = "";
Object.entries(my).forEach(entry => {
mystring = entry[1] + mystring;
});
I would expect that mystring is equal to "jklasdf" and it is. However, I get a flow error on the mystring = ... line. The error states:
Cannot cast
Object.entries(...)[0][1]to string because mixed [1] is incompatible with string
Any thoughts on how to fix this? Thanks!
Object.entriesis anArray<[string, mixed]>so accessingentry[0]should yield astring(reference). Maybe you're trying to accessentry[1](which would have typemixed)? - user11307804