【发布时间】:2020-02-14 01:10:01
【问题描述】:
如何在我的自定义 RxJS 运算符中实现不可为空的类型保护?下一个代码
export const filterNil = <T>() => (source: Observable<T | undefined | null>): Observable<T> => source.pipe(
filter<T>((value: T): value is NonNullable<T> => value !== null && value !== undefined),
);
抛出 ts 错误:
TS2345: Argument of type 'MonoTypeOperatorFunction<T>' is not assignable to parameter of type 'OperatorFunction<T | null | undefined, T>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable<T | null | undefined>' is not assignable to type 'Observable<T>'.
Type 'T | null | undefined' is not assignable to type 'T'.
Type 'undefined' is not assignable to type 'T'.
【问题讨论】:
标签: typescript rxjs