Home > Blockchain >  Type 'AxiosResponse<any>' is missing the following properties from type 'countr
Type 'AxiosResponse<any>' is missing the following properties from type 'countr

Time:10-30

On setState I am getting this TS error:

"Type 'AxiosResponse' is missing the following properties from type 'countries[]': length, pop, push, concat, and 26 more.ts(2740)"

Can anyone suggest what's wrong/where to use :countries[] ?

export interface IProfileEditorState {
  countries: countries[];
}

interface countries {
  countryID: string;
  countryName: string;
  label: astring;
  value: string;
  isDirector: number;
}

// Temp
public getCountrys() {
axios
.get('https://func-myportal-dev.azurewebsites.net/api/GetCountries?code=j0xGK8L6iRXpZqR3DgaDRoI/H/qjGZSGdBPIY9rZU84uH4SUa80noQ==')
.then(res => {
 this.setState({countries: res});
 })
 // Error catching
 .catch(error => this.setState({ error, isLoading: false }));
}

CodePudding user response:

Every Axios method uses generic types so you can do the following:

axios
  .get<countries>('https://func-myportal-dev.azurewebsites.net/api/GetCountries?code=j0xGK8L6iRXpZqR3DgaDRoI/H/qjGZSGdBPIY9rZU84uH4SUa80noQ==')
  .then(res => { /* res.data here is countries type */ })
  • Related