管道(地图)的角度问题
issue in angluar with pipe(map)
我正在尝试学习平均堆栈,但我 运行 遇到了此代码的问题。
它在编译时出现此错误,如果您对如何解决这个问题有想法,我们将不胜感激
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/internal/types").OperatorFunction<{ message: string; posts: any; }, any>' 类型的参数不可分配给 'import("C:/Windows/System32/node_modules/rxjs/dist/types/internal/types").OperatorFunction<{ message: string; posts: any; }, any>'.[=11 类型的参数=]
get<{ message: string; posts:any[] }>
我正在尝试学习平均堆栈,但我 运行 遇到了此代码的问题。
它在编译时出现此错误,如果您对如何解决这个问题有想法,我们将不胜感激
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/internal/types").OperatorFunction<{ message: string; posts: any; }, any>' 类型的参数不可分配给 'import("C:/Windows/System32/node_modules/rxjs/dist/types/internal/types").OperatorFunction<{ message: string; posts: any; }, any>'.[=11 类型的参数=]
get<{ message: string; posts:any[] }>