domains / / axios/axios
Flexible configuration design
Design configuration interfaces to be flexible and extensible rather than overly specific. When creating configuration objects, make configuration parameters optional when possible with sensible defaults and allow for arbitrary additional properties rather than creating specific fields for custom configurations.
Design configuration interfaces to be flexible and extensible rather than overly specific. When creating configuration objects:
- Make configuration parameters optional when possible with sensible defaults
- Allow for arbitrary additional properties rather than creating specific fields for custom configurations
Example - Instead of this:
export interface AxiosRequestConfig<D = any> {
// other properties...
customConfig?: Record<string, any>;
}
// Required configuration parameter
getUri(config: AxiosRequestConfig): string;
Do this:
export interface AxiosRequestConfig<D = any> {
// other properties...
[key: string]: any; // Allow arbitrary properties
}
// Optional configuration parameter
getUri(config?: AxiosRequestConfig): string;
This approach allows consumers to extend configurations naturally without requiring interface changes for each new use case, while maintaining backward compatibility through sensible defaults.