Group items in Typescript with lodash
<p>I need to group a collection of objects by date:</p>

<pre><code>var meetings =
[
   {date:"2001-01-01 13:00", place:"park"},
   {date:"2001-01-01 14:00", place:"school"},
   {date:"2001-01-02 11:00", place:"house"}
];
</code></pre>

<p>so it becomes:</p>

<pre><code>var groupedMeetings = 
[
   {
      day:"2001-01-01", 
      meetings: 
      [
         {date:"2001-01-01 13:00", place:"park"},
         {date:"2001-01-01 14:00", place:"school"}
      ]
   },
   {
      day:"2001-01-02", 
      meetings: 
      [
         {date:"2001-01-02 11:00", place:"house"}
      ]
   }
]
</code></pre>

<p>I was able to group them with _.groupBy and _.map</p>

<pre><code>var g = _.groupBy(meetings, function(i){return getDatePart(i.date);});
var groupedMeetings  = _.map(g, function(items,key){return {day:key, meetings:items};});
</code></pre>

<p>But I have problems with doing the same in Typescript with <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/lodash/lodash.d.ts" rel="noreferrer">https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/lodash/lodash.d.ts</a></p>

<p>First, I declared my classes:</p>

<pre><code>class Meeting
    {
       date: Date,
       place: Meeting[]
    }
class GroupedMeeting
    {
      constructor(private day: Date, private meetings: Meeting[]) {}
    }
</code></pre>

<p>Now I dont know which overload of groupBy to use? And how to map it to list of grouped items?</p>

<pre><code>var grouped: _.Dictionary&lt;Meeting[]&gt; = _.groupBy(meetings, (i: Meeting) =&gt; { return this.getDatePart(i.date); });

var groupedMeetings : GroupedMeeting[] = _.map(grouped, (items: Meeting[], key: Date) =&gt; { return new GroupedMeeting (key, items); });
</code></pre>