I don't actually know what to call the argument to merge in the second line below, but it looks like an array of objects that have a string key. What is the argument called in English, and how do I construct/pass the ...iterables: {[key: string]: V}[]
merge(...iterables: Iterable<K, V>[]): Map<K, V>
merge(...iterables: {[key: string]: V}[]): Map<string, V> // THIS ONE! what?!
The source comes from the ImmutableJS merge documentation.
merge() Returns a new Map resulting from merging the provided Iterables (or JS objects) into this Map. In other words, this takes each entry of each iterable and sets it on this Map.
DISCUSSION If any of the values provided to merge are not Iterable (would return false for Immutable.Iterable.isIterable) then they are deeply converted via Immutable.fromJS before being merged. However, if the value is an Iterable but includes non-iterable JS objects or arrays, those nested values will be preserved.
I understand the first one, but What is going on in the second one? This is my best guess (es6 syntax):
const iterable1 = fromJS([{"other":"b"}])
const merged = fromJS({"self":"a"}).merge(iterable1, iterable ...)
Edit:
After reading the answer, I was confusing (a number of things, but mainly) es6 syntax with typescript syntax. The answer below treats Rest Parameters quite nicely to help with the distinction.
That is called Indexable Types in typescript:
For example:
In the case of the immutable signature:
It means:
The
V
generic constraint is infered to bestring
because of the value in the object that is the parameter forfromJS
, then the rest of the objects need to be string => string as well.Edit
In your example there's no use of the spread operator, what's in use is called Rest Parameters:
Compiles to:
And can be used like so: