@@ -41,22 +41,22 @@ class Collection<ItemType extends ResourceInterface, ResourceType extends Collec
4141 /**
4242 * Returns a promise that resolves to the collection object, once all items have been loaded
4343 */
44- private _itemLoader ( array : Array < ItemType > ) : Promise < this> {
44+ private _itemLoader ( array : Array < ItemType | Link > ) : Promise < this> {
4545 if ( ! this . _containsUnknownEntityReference ( array ) ) {
46- return Promise . resolve ( this ) // we know that this object must be of type CollectionInterface
46+ return Promise . resolve ( this )
4747 }
4848
4949 // eager loading of 'fetchAllUri' (e.g. parent for embedded collections)
5050 if ( this . config . avoidNPlusOneRequests ) {
51- return this . apiActions . reload < ItemType > ( this ) as unknown as Promise < this > // we know that reload resolves to a type CollectionInterface
51+ return this . apiActions . reload < this > ( this )
5252
5353 // no eager loading: replace each reference (Link) with a Resource (ResourceInterface)
5454 } else {
5555 const arrayWithReplacedReferences = this . _replaceEntityReferences ( array )
5656
5757 return Promise . all (
5858 arrayWithReplacedReferences . map ( entry => entry . _meta . load )
59- ) . then ( ( ) => this ) // we know that this object must be of type CollectionInterface
59+ ) . then ( ( ) => this )
6060 }
6161 }
6262
@@ -65,12 +65,10 @@ class Collection<ItemType extends ResourceInterface, ResourceType extends Collec
6565 * (or from the API if necessary), and returns that as a new array. In case some of the entity references in
6666 * the array have not finished loading yet, returns a LoadingCollection instead.
6767 * @param array possibly mixed array of values and references
68- * @param fetchAllUri URI that allows fetching all array items in a single network request, if known
69- * @param fetchAllProperty property in the entity from fetchAllUri that will contain the array
7068 * @returns array the new array with replaced items, or a LoadingCollection if any of the array
7169 * elements is still loading.
7270 */
73- private _mapArrayOfEntityReferences ( array : Array < ItemType > ) : Array < ItemType > {
71+ private _mapArrayOfEntityReferences ( array : Array < Link > ) : Array < ItemType > {
7472 if ( ! this . _containsUnknownEntityReference ( array ) ) {
7573 return this . _replaceEntityReferences ( array )
7674 }
@@ -90,15 +88,15 @@ class Collection<ItemType extends ResourceInterface, ResourceType extends Collec
9088 /**
9189 * Replace each item in array with a proper Resource (or LoadingResource)
9290 */
93- private _replaceEntityReferences ( array : Array < ItemType > ) : Array < ItemType > {
94- const links = array . filter ( entry => isEntityReference ( entry ) ) as unknown as Link [ ]
91+ private _replaceEntityReferences ( array : Array < ItemType | Link > ) : Array < ItemType > {
92+ const links = array . filter ( isEntityReference )
9593 return links . map ( entry => this . apiActions . get < ItemType > ( entry . href ) as ItemType )
9694 }
9795
9896 /**
9997 * Returns true if any of the items within 'array' is not yet known to the API (meaning it has never been loaded)
10098 */
101- private _containsUnknownEntityReference ( array : Array < ItemType > ) : boolean {
99+ private _containsUnknownEntityReference ( array : Array < ItemType | Link > ) : array is Array < Link > {
102100 return array . some ( entry => isEntityReference ( entry ) && this . apiActions . isUnknown ( entry . href ) )
103101 }
104102}
0 commit comments