类型ɺxiosResponse<any>‘缺少类型’countries[]‘的以下属性: length,pop,push,concat

问题描述

每个Axios method都使用generic types,因此您可以执行以下操作:

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

解决方法

在setState上,我收到以下TS错误:

“类型'AxiosResponse‘缺少类型’countries[]‘的以下属性:长度、pop、push、concat和26 more.ts(2740)”

谁能建议一下哪里出了问题/在哪里使用: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 }));
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...