I'm building the API to connect my react app with my backend service and I want to use typescript to specify the type of data inside my Axios request. How can I update the type of data inside Axios response without modifying the other fields (see getAllProjects in the code below)?
class MyApi {
constructor(token: string | null) {
let headers: any = {
'Content-Type': 'application/json',
};
if (token) {
headers = {
...headers, //append other basic proprieties
'Authorization': 'Token ' + token
}
}
this.baseEndpoint = axios.create({
baseURL: `${baseURL}`,
headers: headers
});
}
//DATA
const getAllProjects = async () : Promise<AxiosResponse<?????>> => this.baseEndpoint.get('/projects/');
}
Simply assigning the desired type (suppose data: string[] for this example) throws the following error:
Argument of type 'string[]' is not assignable to parameter of type 'SetStateAction<never[]>'.
Type 'string[]' is not assignable to type 'never[]'.
Type 'string' is not assignable to type 'never'.