Prompt
Design API interfaces with strong type safety while maintaining excellent developer experience. Prefer explicit types over loose ones to enable better IDE support and catch errors at compile time.
Key principles:
- Use explicit generic parameters with meaningful names
- Prefer
unknownoveranyfor better type safety - Use intersection types when combining interface properties
- Avoid string literals when specific types are available
Example:
// ❌ Avoid
interface ApiConfig {
headers?: Record<string, any>;
data?: any;
}
// ✅ Better
interface ApiConfig<ResponseData = unknown, RequestData = unknown> {
headers?: HeadersDefaults & RequestHeaders;
data?: RequestData;
response?: AxiosResponse<ResponseData>;
}
This approach provides better IDE autocompletion, makes the code more maintainable, and catches potential type errors during development rather than at runtime.