@@ -319,7 +319,7 @@ export abstract class AbstractSearch<T extends Entity = Record<string, any>> {
319
319
* @returns An array of key names matching the query.
320
320
*/
321
321
async allKeys ( options = { pageSize : 10 } ) : Promise < string [ ] > {
322
- return ( await this . allThings ( this . pageOfKeys , options ) ) as string [ ] ;
322
+ return this . allThings ( this . pageOfKeys , options ) ;
323
323
}
324
324
325
325
/**
@@ -442,22 +442,24 @@ export abstract class AbstractSearch<T extends Entity = Record<string, any>> {
442
442
return await this . allKeys ( options ) ;
443
443
}
444
444
445
- private async allThings (
446
- pageFn : Function ,
445
+ private async allThings < R extends T [ ] | string [ ] > (
446
+ pageFn : ( offset : number , pageSide : number ) => Promise < R > ,
447
447
options = { pageSize : 10 } ,
448
- ) : Promise < T [ ] | string [ ] > {
449
- const things = [ ] ;
448
+ ) : Promise < R > {
449
+ // TypeScript is just being mean in this function. The internal logic will be fine in runtime,
450
+ // However, it is important during future changes to double check your work.
451
+ let things : unknown [ ] = [ ] ;
450
452
let offset = 0 ;
451
453
const pageSize = options . pageSize ;
452
454
453
455
while ( true ) {
454
456
const foundThings = await pageFn . call ( this , offset , pageSize ) ;
455
- things . push ( ...foundThings ) ;
457
+ things . push ( ...( foundThings as unknown [ ] ) ) ;
456
458
if ( foundThings . length < pageSize ) break ;
457
459
offset += pageSize ;
458
460
}
459
461
460
- return things ;
462
+ return things as R ;
461
463
}
462
464
463
465
private async callSearch (
0 commit comments