简体   繁体   English

管道角度问题(地图)

[英]issue in angluar with pipe(map)

im trying to learn the mean stack and i have run in to an issue with this code.我试图学习平均堆栈,但我遇到了这个代码的问题。

its giving this error when compiling if you have an idea on how to solve this it would be much appreciated如果您对如何解决此问题有想法,则在编译时会出现此错误,我们将不胜感激

 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]);
      });
  }

Error: src/app/posts/posts.service.ts:20:13 - error TS2345: Argument of type 'import("C:/Windows/System32/metric-server/node_modules/rxjs/dist/types/internal/types").OperatorFunction<{ message: string;错误:src/app/posts/posts.service.ts:20:13 - 错误 TS2345:类型参数 'import("C:/Windows/System32/metric-server/node_modules/rxjs/dist/types/internal/types ").OperatorFunction<{ 消息:字符串; posts: any;职位:任何; }, any>' is not assignable to parameter of type 'import("C:/Windows/System32/node_modules/rxjs/dist/types/internal/types").OperatorFunction<{ message: string; }, any>' 不能分配给类型 'import("C:/Windows/System32/node_modules/rxjs/dist/types/internal/types").OperatorFunction<{ message: string; posts: any;职位:任何; }, any>'. },任何>'。

get<{ message: string; posts:any[] }>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM