@@ -2,11 +2,12 @@ import {
22 AccountApiParameters ,
33 AccountInformation ,
44 BaseResponse ,
5+ EngineName ,
6+ EngineParameters ,
57 GetBySearchIdParameters ,
68 Locations ,
79 LocationsApiParameters ,
810} from "./types.ts" ;
9- import { EngineMap } from "./engines/engine_map.ts" ;
1011import {
1112 _internals ,
1213 execute ,
@@ -69,11 +70,12 @@ const SEARCH_ARCHIVE_PATH = `/searches`;
6970 * });
7071 */
7172export async function getJson <
72- E extends keyof EngineMap ,
73+ E extends EngineName = EngineName ,
74+ P extends EngineParameters < E > = EngineParameters < E > ,
7375> (
7476 engine : E ,
75- parameters : EngineMap [ E ] [ "parameters" ] ,
76- callback ?: ( json : BaseResponse < EngineMap [ E ] [ "parameters" ] > ) => void ,
77+ parameters : P ,
78+ callback ?: ( json : BaseResponse < P > ) => void ,
7779) {
7880 const key = validateApiKey ( parameters . api_key , true ) ;
7981 const timeout = validateTimeout ( parameters . timeout ) ;
@@ -87,9 +89,7 @@ export async function getJson<
8789 } ,
8890 timeout ,
8991 ) ;
90- const json = await response . json ( ) as BaseResponse <
91- EngineMap [ E ] [ "parameters" ]
92- > ;
92+ const json = await response . json ( ) as BaseResponse < P > ;
9393 const nextParametersFromResponse = extractNextParameters < E > ( json ) ;
9494 if (
9595 // https://github.com/serpapi/public-roadmap/issues/562
@@ -126,9 +126,12 @@ export async function getJson<
126126 * // callback
127127 * getHtml("google", { api_key: API_KEY, q: "coffee" }, console.log);
128128 */
129- export async function getHtml < E extends keyof EngineMap > (
129+ export async function getHtml <
130+ E extends EngineName = EngineName ,
131+ P extends EngineParameters < E > = EngineParameters < E > ,
132+ > (
130133 engine : E ,
131- parameters : EngineMap [ E ] [ "parameters" ] ,
134+ parameters : P ,
132135 callback ?: ( html : string ) => void ,
133136) {
134137 const key = validateApiKey ( parameters . api_key , true ) ;
0 commit comments