Design API parameters to be self-documenting and minimize cognitive overhead. Avoid boolean parameters in favor of descriptive enums or string literals, leverage type inference where possible, and prefer clean parameter passing over state mutation patterns.
Key principles:
Example of boolean parameter improvement:
// Instead of:
async function processSnapshot(updateIndex: boolean) {
// unclear what true/false means
}
// Use descriptive options:
async function processSnapshot(indexBehavior: 'updateAnonymousSnapshotIndex' | 'dontUpdateAnonymousSnapshotIndex') {
// behavior is immediately clear
}
Example of parameter inference:
// Instead of requiring explicit contentType:
await testInfo.attach('report.html', {
path: attachmentFile,
contentType: 'text/html' // redundant
});
// Infer from file extension:
await testInfo.attach('report.html', {
path: attachmentFile // contentType inferred from .html extension
});
This approach reduces API surface area, prevents misuse, and makes code more maintainable by encoding intent directly in the parameter names and types.
Enter the URL of a public GitHub repository