From c98c6a31c43f5f270425751b3b38e42cf276337c Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Tue, 3 Mar 2020 10:48:50 +0100 Subject: [PATCH] fix: typings for paginate --- source/create.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/create.ts b/source/create.ts index e59a39ee6..cc85201d6 100644 --- a/source/create.ts +++ b/source/create.ts @@ -61,9 +61,11 @@ export interface GotRequestMethod { (url: string | Merge, options?: Merge): ProxyStream; } +export type GotPaginateOptions = Omit> & PaginationOptions + export interface GotPaginate { - (url: URLOrOptions & PaginationOptions, options?: Options & PaginationOptions): AsyncIterableIterator; - all(url: URLOrOptions & PaginationOptions, options?: Options & PaginationOptions): Promise; + (url: string | GotPaginateOptions, options?: GotPaginateOptions): AsyncIterableIterator; + all(url: string | GotPaginateOptions, options?: GotPaginateOptions): Promise; } export interface Got extends Record, GotRequestMethod { @@ -198,8 +200,8 @@ const create = (defaults: Defaults): Got => { } // @ts-ignore The missing property is added below - got.paginate = async function * (url: URLOrOptions, options?: Options) { - let normalizedOptions = normalizeArguments(url, options, defaults); + got.paginate = async function * (url: string | Omit> & PaginationOptions, options?: Omit> & PaginationOptions) { + let normalizedOptions = normalizeArguments(url as URLOrOptions, options as Options, defaults); const pagination = normalizedOptions._pagination!; @@ -245,11 +247,11 @@ const create = (defaults: Defaults): Got => { } }; - got.paginate.all = async (url: URLOrOptions, options?: Options) => { + got.paginate.all = async (url: string | GotPaginateOptions, options?: GotPaginateOptions) => { const results: T[] = []; - for await (const item of got.paginate(url, options)) { - results.push(item as T); + for await (const item of got.paginate(url, options)) { + results.push(item); } return results;