Skip to content

feat: typed Google Search parameters and responses (fixes #33)#37

Open
kenrogers wants to merge 1 commit intoserpapi:masterfrom
kenrogers:feat/improved-typescript-types
Open

feat: typed Google Search parameters and responses (fixes #33)#37
kenrogers wants to merge 1 commit intoserpapi:masterfrom
kenrogers:feat/improved-typescript-types

Conversation

@kenrogers
Copy link
Copy Markdown

@kenrogers kenrogers commented Mar 28, 2026

Summary

  • Added GoogleSearchParameters and GoogleSearchResponse typed interfaces matching the Google Search API docs
  • Added a typed overload to getJson() — when you pass engine: "google", you get autocomplete and typed responses
  • Generic EngineParameters and BaseResponse preserved for backwards compatibility with all other engines
  • Includes typed interfaces for OrganicResult, KnowledgeGraph, RelatedQuestion, SearchMetadata, SearchInformation, and SearchParameters

Context

This is a starting point for addressing #33. The current types (EngineParameters = Record<string, any>) provide no autocomplete, no typo protection, and no response typing. As the issue notes, this is effectively the same as not having TypeScript support.

Typing every engine at once felt too large for a single PR. Instead, this PR is meant to be a pattern that can be incrementally applied to other engines.

Approach

Each engine gets its own file under src/engines/. Adding Bing, YouTube, Amazon, etc. follows the same pattern: one file per engine, one typed overload per function.

The index signature [key: string]: unknown on the response type ensures new API fields work without SDK updates. This was a design decision that could be re-evaluated depending on desired maintenance burden for the SDK.

Replace Record<string, any> with GoogleSearchParameters and
GoogleSearchResponse for the Google engine. Adds a typed overload
to getJson() so users get autocomplete and validation when passing
engine: "google". Generic types preserved for backwards compatibility.

Pattern is extensible to other engines (Bing, YouTube, etc.) by
adding files under src/engines/.

Fixes serpapi#33
@kenrogers kenrogers marked this pull request as ready for review March 28, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant