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.
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:
function(param1, param2, param3)
, use function({ param1, param2, param3 })
for better readability and extensibilityany
types with specific interfaces like GotoOptions
to provide better developer experience and catch errors earlycontext.pages()[index]
instead of direct page references{ 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.
Enter the URL of a public GitHub repository