属性"_body"在“响应"类型上不存在 [英] Property '_body' does not exist on type 'Response'
问题描述
我正在使用Angular 2,并且在使用可观察的Property '_body' does not exist on type 'Response'
时遇到此错误.代码在下面
I am using Angular 2 and getting this error when using an observable Property '_body' does not exist on type 'Response'
. The code is below
this.securitiesService.getMarketMovers()
.subscribe(data => {
console.log(JSON.parse(data._body))
});
getMarketMovers函数就是这样:
The getMarketMovers function is simply this:
getMarketMovers() {
return this._http.get('...url address...')
}
我尝试将data
设置为键入any
,但这对我不起作用.代码可以工作,并且数据上肯定有一个_body
属性,但是它仍然会引发错误,并且我无法使用此错误进行构建.
I have tried to set data
to type any
but that isn't working for me. The code works and there is definitely a _body
property on data but it still throws there error and I cant build with this error.
非常感谢您的帮助.
推荐答案
更新
另一种方法是明确告诉TypeScript我们对执行严格的类型检查不感兴趣.
Another way, is to explicitly tell TypeScript that we’re not interested in doing strict type checking.
(<any>data)._body
原始
此data["_body"]
应该可以工作.
这篇关于属性"_body"在“响应"类型上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!