属性 'map' 在类型 'Object' 上不存在 'Object'.ts(2339)

Property 'map' does not exist on type 'Object'.ts(2339)

我正在开发一个 Ionic 5 应用程序,我遇到了这样的错误。

我试过这里的解决方法,但是这次他找不到第一张图

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
//import { map } from 'lodash';
@Injectable({
  providedIn: 'root'
})
export class UnitService {
baseUrl='https://jsonplaceholder.typicode.com';
  constructor(private http:HttpClient) { }

  getUnit(){
    return this.http.get(`${this.baseUrl}/users`).pipe(
      map(unit => {
        return unit.map((un, index) => {
          un.unIndex = index + 1;
          return un;
        });
      })
    )
  }
}

我该如何解决这个错误

您需要指定 map() 将接收一个数组。将您的代码更改为:

map((unit: any[]) => {
 ...
}

Here's 相同的工作 stackblitz。