【问题标题】:issue in angluar with pipe(map)管道角度问题(地图)
【发布时间】:2022-01-07 11:00:13
【问题描述】:

我正在尝试学习平均堆栈,但我遇到了此代码的问题。

如果您知道如何解决此问题,在编译时会出现此错误,我们将不胜感激

 getPosts() {
    this.http
      .get<{ message: string; posts:any }>(
        "http://localhost:3000/api/posts"
      )
      .pipe(map((postData) => {
        return postData.posts.map(post => {
          return {
            title: post.title,
            content: post.content,
            id: post._id
          };
        });
      }))
      .subscribe(transformedPosts => {
        this.posts = transformedPosts;
        this.postsUpdated.next([...this.posts]);
      });
  }

错误:src/app/posts/posts.service.ts:20:13 - 错误 TS2345: 类型参数 'import("C:/Windows/System32/metric-server/node_modules/rxjs/dist/types/内部/类型").OperatorFunction' 不能分配给类型为 'import("C:/Windows/System32/node_modules/rxjs/dist/types/internal/types").OperatorFunction'。

【问题讨论】:

    标签: node.js angular typescript mean-stack


    【解决方案1】:
    get<{ message: string; posts:any[] }>
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 2018-01-30
    • 2018-06-12
    相关资源
    最近更新 更多