属性"_body"在“响应"类型上不存在 [英] Property '_body' does not exist on type 'Response'

查看:101
本文介绍了属性"_body"在“响应"类型上不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆