【发布时间】:2015-08-10 18:10:12
【问题描述】:
我怀疑我犯了一个错误,但我无法让以下内容通过类型检查。我最终得到Property 'map' does not exist for type 'Restos'。我已经按照TS教程设置了界面,所以感觉好像map没有默认包含(我在tsconfig中有"target": "es6")
interface Resto {
rname:String,
qname:String,
tel:String
}
interface Restos {
[index:number]:Resto;
}
class MainController {
headline: String;
rnames: [String];
constructor($http : ng.IHttpService) {
this.headline = "hello world";
$http.get('http://afbackend.herokuapp.com/api/restos')
.success( (res:Restos) => {
console.log(res);
this.rnames = res.map(r => r.rname)
^^^
});
}
}
【问题讨论】:
-
在您的 Restos 界面中,map 方法在哪里?也许只是使用 Resto[] 而不是 Restos。
标签: typescript