It's intended for more complex situations where you have some entry/Entry function/class with a generic for the key type that serves to "capture" it, otherwise we'd just get Record<string, Entry>.
The type if hovered over it will just say: RecordFromArray<...bunch of confusing types...> but it's just this again except each value is an instance of Entry:
Creates a map from an array (of objects) T, keyed by it's object's TKey property value, with values of TValue.
This is a simplified example to get the point across.
A variable of type
Entries
now autocompletes properly, e.g.entries.
suggestsa
andb
because it's type looks like this:The type could be made stricter (e.g.
a: {id: "a"}
) but this is usually inconvenient. SoTKey
is always turned into a primitive type.The type of the final value can also be overriden (except for the original key, which unfortunately you will get no warning if you try to override).
It's intended for more complex situations where you have some
entry
/Entry
function/class with a generic for the key type that serves to "capture" it, otherwise we'd just getRecord<string, Entry>
.Using classes:
The type if hovered over it will just say:
RecordFromArray<...bunch of confusing types...>
but it's just this again except each value is an instance ofEntry
:Using functions:
Here the types will be slightly clearer since there isn't a class wrapping each entry.