首页 新闻 会员 周边 捐助

angular 项目中遇到的 typescript 问题:如何将 Array 转换为 List

0
悬赏园豆:30 [已解决问题] 解决于 2025-05-11 16:27

下面的代码中 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.

请问如何用最简单的方法完成数组到列表的转换?

dudu的主页 dudu | 高人七级 | 园豆:24691
提问于:2025-05-11 16:09
< >
分享
最佳答案
0

通过 map(List) 解决了

this.categoryStore.categories$
    .pipe(
        takeUntilDestroyed(this.destroyRef),
        map(List)
    )
    .subscribe(async x => {
        this.categories = x;
    });
dudu | 高人七级 |园豆:24691 | 2025-05-11 16:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册