You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is now reported as an error because .first() might return undefined.
It would be nice to implement NotEmpty collections in that case.
Here is a quick implementation in my codebase:
import{Collection,List,Set}from'immutable';exportinterfaceNotEmptyCollection<K,V>extendsCollection<K,V>{first(): V;last(): V;}exportinterfaceNotEmptyList<T>extendsList<T>{first(): T;last(): T;}exportinterfaceNotEmptySet<T>extendsSet<T>{first(): T;last(): T;}exportfunctioncollectionHasItem<T>(list: List<T>): list is NotEmptyList<T>;exportfunctioncollectionHasItem<T>(list: Set<T>): list is NotEmptySet<T>;exportfunctioncollectionHasItem<K,T>(list: Collection<K,T>): list is NotEmptyCollection<K,T>{returnlist.count()>0;}exportfunctioncollectionHasExactlyOneItem<T>(list: List<T>): list is NotEmptyList<T>;exportfunctioncollectionHasExactlyOneItem<T>(list: Set<T>): list is NotEmptySet<T>;exportfunctioncollectionHasExactlyOneItem<K,T>(list: Collection<K,T>): list is NotEmptyCollection<K,T>{returnlist.count()===1;}
It would be great for groupBy function too:
someList.groupBy((i)=>i.category).map((l: List<Item>)=>l.first())// reported as error, but it can't be
The text was updated successfully, but these errors were encountered:
#2001 was a nice addition, but now there is a lot of issue reported like this:
This is now reported as an error because
.first()
might return undefined.It would be nice to implement
NotEmpty
collections in that case.Here is a quick implementation in my codebase:
It would be great for
groupBy
function too:The text was updated successfully, but these errors were encountered: