Open Raynos opened 4 years ago
Does hegel support objects with arbitary keys ?
No. It supports it only inside the d.ts
typing (via $Collection
, but you can't create value for the type).
Our position is: if you need key-value storage - use Map
.
But, we try to implement it inside inner typing to have the ability do like this
Using {}
as a dictionary instead of Map
is important for using hegelJS on existing codebases.
I want to look at taking an existing JS library like https://github.com/Raynos/error/blob/master/index.js#L62-L76 and porting it to hegel.
Here is another example ( https://github.com/Raynos/fake-ses/blob/master/index.js#L112-L120 ).
I understand {}
or Object.create(null)
might not be as nice as Map
but it should be supported.
@JSMonk well objects with arbitrary keys sounds like a bad idea but Array is a object and a collection and we are okay with it
both flow and typescript supports this and it's common pattern in js so you really need to consider supporting it
Okay, I will add the ability to use $Collection
with objects soon. Thank you for the arguments and issue ^_^
Does hegel support objects with arbitary keys ?
Like
An object with an arbitary key (
string
ornumber
I guess ... ) and a known valueT
, in the example above string but could by anything.This was not found on https://hegel.js.org/docs/object-types