Back to all reviewers

API parameter design

browserbase/stagehand
Based on 4 comments
TypeScript

Design API methods with structured object parameters instead of ordered parameters or loose typing. Use proper TypeScript types rather than `any`, and consider parameter patterns that enhance safety and flexibility.

API TypeScript

Reviewer Prompt

Design API methods with structured object parameters instead of ordered parameters or loose typing. Use proper TypeScript types rather than any, and consider parameter patterns that enhance safety and flexibility.

Key principles:

  • Object parameters over ordered parameters: Instead of function(param1, param2, param3), use function({ param1, param2, param3 }) for better readability and extensibility
  • Proper typing: Replace any types with specific interfaces like GotoOptions to provide better developer experience and catch errors early
  • Safety through design: Consider index-based parameters or other patterns that prevent edge cases, such as context.pages()[index] instead of direct page references
  • Support for templating: Design APIs that can handle dynamic content through structured approaches like { action: "search for %query%", variables: { query: "value" } }

Example transformation:

// Before: Ordered parameters with loose typing
page.goto = async (url: string, options?: any) => { ... }

// After: Proper typing and structured approach
page.goto = async (url: string, options?: GotoOptions) => { ... }

// Before: Multiple ordered parameters
resolveLLMClient(llmClient, modelName, requestId)

// After: Object parameter with proper typing
resolveLLMClient({ 
  llmProvider, 
  modelName, 
  requestId 
}: { 
  llmClient?: LLMClient, 
  modelName?: AvailableModel, 
  requestId?: string 
})

This approach improves API discoverability, reduces parameter ordering mistakes, and makes future extensions easier without breaking existing code.

4
Comments Analyzed
TypeScript
Primary Language
API
Category

Source Discussions