下面的代码中 categories$
的类型是 Observable<BlogCategoryEditDto[]>
,this.categories
的类型是 List<BlogCategoryEditDto>
this.categoryStore.categories$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(async x => {
this.categories = x;
});
出现下面的编译错误
Type 'BlogCategoryEditDto[]' is missing the following properties from type 'List<BlogCategoryEditDto>': size, set, delete, remove, and 80 more.
请问如何用最简单的方法完成数组到列表的转换?
通过 map(List)
解决了
this.categoryStore.categories$
.pipe(
takeUntilDestroyed(this.destroyRef),
map(List)
)
.subscribe(async x => {
this.categories = x;
});