下面的 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)
)
);
请问如何解决?
参考 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)
);