Angular 6属性“地图"在类型“对象"上不存在 [英] Angular 6 Property 'map' does not exist on type 'Object'

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

问题描述

我有一个api,它返回的对象/数组是这样的:

I have a api which return objects / array like this:

(2) [{...}, {...}]      object

  0: {a: '1', b: {id: '1'}}
  1: {a: '2', b: {id: '2'}}

因此,它看起来像对象数组(但调试显示为对象").

So it looks like array of objects (but debuges says 'Object').

所以在我的代码中,我有:

So in my code I have:

return this.http.get(this.url).pipe(
  map(datas => {
    return datas.map(data => {
      let object = {
        a: data['a'],
        b: data['b']['id'],
      }
      return object;
    })
  })
);

但是在那里:

return datas.map(data => {

我遇到一个错误:

Property 'map' does not exist on type 'Object'.

但是应用程序运行良好,可以正确显示此数据.但是这个错误很烦人.

But application is working well is correctly shows this data. But this error is annoying.

我该怎么办?

推荐答案

以下操作符在RXJS6中已重命名

The following operators were renamed in RXJS6

catch() => catchError()
do() => tap()
finally() => finalize()
switch() => switchAll()

另外,重命名/重构了一些Observable-creation方法:

Additionally, some Observable-creation methods were renamed/ refactored:

throw() => throwError()
fromPromise() => from() (this automatically detects the type)

FOR MAP 语法

import { map } from 'rxjs/operators';

myObservable
  .pipe(map(data => data * 2))
  .subscribe(...);

这篇关于Angular 6属性“地图"在类型“对象"上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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