Ugh, I am struggling to get a simple for loop working with immutable-js objects, it causes many of my refactored validator tests to fail 😓
2024-06-21 17333, 2024
kellnerd[m]
We should really migrate away from this ancient version 3.x which we are using, I am getting TypeError: values is not iterable when I try a for-of-loop...
2024-06-21 17319, 2024
bitmap[m] joined the channel
2024-06-21 17319, 2024
bitmap[m]
What's the data type of values? (I've used immutable-js in the past though my memory of it is a bit fuzzy.)
2024-06-21 17303, 2024
kellnerd[m]
That's the question, immutable-js does some weird shit to obfuscate whether something is array-like or map-like, I'm trying to find that out currently.
2024-06-21 17325, 2024
kellnerd[m]
And v3 is even weirder than v4 as its main object type is called Iterable, which is not (fully?) implementing the ES iterable protocol.
2024-06-21 17333, 2024
kellnerd[m]
I am basically trying to replace [this `every` call to a boolean validation function](https://github.com/metabrainz/bookbrain… (a weird mix of immutable and lodash) with a plain loop which is calling a throwing validation function.
2024-06-21 17348, 2024
monkey[m]
I remember there was a custom function to iterate over the results
The issue is that the function's parameters are annotated misleadingly, it says `any[]` but it is really something like `Record<any, any> | Immutable.Iterable`.
2024-06-21 17330, 2024
kellnerd[m]
Now 70 failing tests pass again, only 5 remaining
2024-06-21 17352, 2024
monkey[m]
Phew
2024-06-21 17358, 2024
monkey[m]
Must feel good :)
2024-06-21 17309, 2024
reosarevok[m] joined the channel
2024-06-21 17310, 2024
reosarevok[m]
I'll take examples of how any is useless and dangerous for $500
2024-06-21 17317, 2024
bitmap[m]
I thought Record was also supposed to be iterable though 🤔
2024-06-21 17312, 2024
kellnerd[m]
Its keys are iterable with for-in, but not its values, for-of throws.
2024-06-21 17341, 2024
kellnerd[m]
I had to use the following:... (full message at <https://matrix.chatbrainz.org/_matrix/media/v3/download/chatbrainz.org/YyYNHueBatsquaJTlATcPiRN>)
2024-06-21 17329, 2024
bitmap[m]
Ah, IIRC for-of on a Record would iterate over [key, value] pairs, but maybe not in your version
2024-06-21 17357, 2024
bitmap[m]
But that makes sense if you want only the values anyway
2024-06-21 17344, 2024
anonn has quit
2024-06-21 17324, 2024
kellnerd[m]
Phew, fixing the last five failing tests took a bit longer because their expected behaviour was a bit inconsistent and I broke it while refactoring. I've left comments about these, so we can discuss whether these test cases are worth changing.