类型'对象'上不存在Angular 6属性'map'

per*_*tor 4 angular6

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

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

  0: {a: '1', b: {id: '1'}}
  1: {a: '2', b: {id: '2'}}
Run Code Online (Sandbox Code Playgroud)

所以它看起来像对象的数组(但是debuges说'对象').

所以在我的代码中我有:

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

但那里:

return datas.map(data => {
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

Property 'map' does not exist on type 'Object'.
Run Code Online (Sandbox Code Playgroud)

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

我能做什么?

Vig*_*esh 5

以下运算符在RXJS6中重命名

catch() => catchError()
do() => tap()
finally() => finalize()
switch() => switchAll()
Run Code Online (Sandbox Code Playgroud)

此外,一些Observable创建方法被重命名/重构:

throw() => throwError()
fromPromise() => from() (this automatically detects the type)
Run Code Online (Sandbox Code Playgroud)

FOR MAP语法

import { map } from 'rxjs/operators';

myObservable
  .pipe(map(data => data * 2))
  .subscribe(...);
Run Code Online (Sandbox Code Playgroud)


小智 0

尝试这个:

npm install rxjs@6 rxjs-compat@6 --saven

请访问Angular 2 beta.17:“Observable<Response>”类型上不存在属性“map”以获取更多说明。