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

查看:27
本文介绍了类型“对象"上不存在 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 创建方法被重命名/重构:

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天全站免登陆