首页 新闻 会员 周边

Angular: "Cannot read properties of null (reading 'filter')"

0
悬赏园豆:30 [已解决问题] 解决于 2023-07-17 21:26

下面的 typescript 代码在运行时会出现错误 "Cannot read properties of null (reading 'filter')"

const preference = await firstValueFrom(
    this.preference$.pipe(
        filter((x): x is PreferencesDto => isObject(x)),
        timeout(5000),
        this.valueOnError<false>(false, false)
    )
);

请问如何解决?

dudu的主页 dudu | 高人七级 | 园豆:30943
提问于:2023-07-17 20:52
< >
分享
最佳答案
0

参考 https://stackoverflow.com/a/68726123 用 skipWhile 解决了

const preference = await firstValueFrom(
    this.preference$.pipe(skipWhile(x => x === null)).pipe(
        filter((x): x is PreferencesDto => isObject(x)),
        timeout(5000),
        this.valueOnError<false>(false, false)
    );
dudu | 高人七级 |园豆:30943 | 2023-07-17 21:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册