I was reading this article about how to use Axios with TypeScript and I had a question about the methods declaration, for example:
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R> {
return this.http.get<T, R>(url, config);
}
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R> {
return this.http.delete<T, R>(url, config);
}
Now, what I miss to understand is the this syntax:
<T = any, R = AxiosResponse<T>>
Why is the T equal to any, isn't it the concept of Generics that T can be anything? Why do I need to specify it? Is it for readability?
Also why is R equals AxiosResponse<T>? Couldn't I just say that the return type of the function is Promise<AxiosResponse<T>>, is it also the sake of writing less code in the return type?
function(x: number = 1) { ... }, it doesn't meanxhas to be 1, it means thatxis 1 unless you say otherwise.