File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ export async function getJson<
7575> (
7676 engine : E ,
7777 parameters : P ,
78- callback ?: ( json : BaseResponse < P > ) => void ,
78+ callback ?: ( json : BaseResponse < E > ) => void ,
7979) {
8080 const key = validateApiKey ( parameters . api_key , true ) ;
8181 const timeout = validateTimeout ( parameters . timeout ) ;
@@ -89,7 +89,7 @@ export async function getJson<
8989 } ,
9090 timeout ,
9191 ) ;
92- const json = await response . json ( ) as BaseResponse < P > ;
92+ const json = await response . json ( ) as BaseResponse < E > ;
9393 const nextParametersFromResponse = extractNextParameters < E > ( json ) ;
9494 if (
9595 // https://github.com/serpapi/public-roadmap/issues/562
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export type EngineParameters<
5353 : BaseParameters & Record < string , unknown > ;
5454} [ E ] ;
5555
56- export type BaseResponse < P = Record < string , unknown > > = {
56+ export type BaseResponse < E extends EngineName = EngineName > = {
5757 search_metadata : {
5858 id : string ;
5959 status : "Queued" | "Processing" | "Success" ;
@@ -63,14 +63,15 @@ export type BaseResponse<P = Record<string, unknown>> = {
6363 raw_html_file : string ;
6464 total_time_taken : number ;
6565 } ;
66- search_parameters :
67- & { engine : string }
68- & Omit < BaseParameters & P , "api_key" | "no_cache" | "async" | "timeout" > ;
66+ search_parameters : Omit <
67+ EngineParameters < E > ,
68+ "api_key" | "no_cache" | "async" | "timeout"
69+ > ;
6970 serpapi_pagination ?: { next : string } ;
7071 pagination ?: { next : string } ;
7172 next ?: (
72- callback ?: ( json : BaseResponse < P > ) => void ,
73- ) => Promise < BaseResponse < P > > ;
73+ callback ?: ( json : BaseResponse < E > ) => void ,
74+ ) => Promise < BaseResponse < E > > ;
7475 // deno-lint-ignore no-explicit-any
7576 [ key : string ] : any ; // TODO(seb): use recursive type
7677} ;
You can’t perform that action at this time.
0 commit comments