Skip to content

Commit 94f6b8f

Browse files
fixed allThings typing
1 parent e37ef9b commit 94f6b8f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/search/search.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export abstract class AbstractSearch<T extends Entity = Record<string, any>> {
319319
* @returns An array of key names matching the query.
320320
*/
321321
async allKeys(options = { pageSize: 10 }): Promise<string[]> {
322-
return (await this.allThings(this.pageOfKeys, options)) as string[];
322+
return this.allThings(this.pageOfKeys, options);
323323
}
324324

325325
/**
@@ -442,22 +442,24 @@ export abstract class AbstractSearch<T extends Entity = Record<string, any>> {
442442
return await this.allKeys(options);
443443
}
444444

445-
private async allThings(
446-
pageFn: Function,
445+
private async allThings<R extends T[] | string[]>(
446+
pageFn: (offset: number, pageSide: number) => Promise<R>,
447447
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[] = [];
450452
let offset = 0;
451453
const pageSize = options.pageSize;
452454

453455
while (true) {
454456
const foundThings = await pageFn.call(this, offset, pageSize);
455-
things.push(...foundThings);
457+
things.push(...(foundThings as unknown[]));
456458
if (foundThings.length < pageSize) break;
457459
offset += pageSize;
458460
}
459461

460-
return things;
462+
return things as R;
461463
}
462464

463465
private async callSearch(

0 commit comments

Comments
 (0)