I'm feeling the same and wondering the same, did you ended up trying this, and if yes, do you have some advice on how to manage this particular use case ?
Serialization might not behave as you would expect (JSON.stringify)
Actually, my implementation idea relying on Proxy don't have this issue.
As for other implementations, they do have this issue, but as they say, hybrid array use cases don't generally involve the need to stringify, and even when they do, using Object.defineProperty with { enumerable: false } (or replacing the toJSON method) would fix it.
3rd-party functions might not be able to deal with your data structure properly (again, potentially unexpected behavior).
You canât easily access array methods (find, filter, map etc).
Actually, it would still be an Array, so no, there shouldn't be any problems, and yes, those methods definitely work, which is precisely what said I want to achieve.
How do you distinguish between ID access and index access?
If your IDs are integers then there is no need for an hybrid at all, precisely because all you have to do is put each item at the same position as their ID.
Itâs harder to reason about access time of lookups. However, this might not be a concern of yours.
I'll definitely run benchmarks so that users would be aware of performance losses, if any. But use cases of hybrid arrays are mostly small datasets so it usually shouldn't be a concern indeed.
It may cause confusion if youâre working with other developers.
If I implement this, it will be as a documented and commented package, so it shouldn't be that much of a problem.
My goal is to be able to both easily get an item by ID (using data[id]) and easily get an item by properties (using data.find()).
Meanwhile, just like Object requires Object.values(object) before calling find, Map requires [...map.values()], and it also have the additional inconvenient of requiring a call to map.get to get an item by ID, so no, it's even worse for my goal, but thanks.
I'm not a TypeScript person, sorry. đ