我该如何解决:
TS2345: Argument of type '() => Observable<R | undefined>' is not assignable to parameter of type '() => void | Subscribable<never> | Subscribable<R> | PromiseLike<R> | InteropObservable<R>'. Type 'Observable<R | undefined>' is not assignable to type 'void | Subscribable<never> | Subscribable<R> | PromiseLike<R> | InteropObservable<R>'. Type 'Observable<R | undefined>' is not assignable to type 'InteropObservable<R>'. Property '[Symbol.observable]' is missing in type 'Observable<R| undefined>
这是来自
public open<T, D, R>(
templateOrComponentRef: TemplateRef<T> | ComponentType<T>,
config: MatDialogConfig<D>,
): Observable<R> {
return defer<R>(() => {
const ref = this.create<T, D, R>(templateOrComponentRef, config);
return ref.afterClosed();
});
}
恰好来自() => {
位置:
public create<T, D, R>(
templateOrComponentRef: TemplateRef<T> | ComponentType<T>,
config: MatDialogConfig<D>,
): MatDialogRef<T, R> {
return this.dialog.open<T, D>(templateOrComponentRef, config);
}
使用角度6.1.3
答案 0 :(得分:0)
好,所以我找到了解决方法:
public open<T, D, R>(
templateOrComponentRef: TemplateRef<T> | ComponentType<T>,
config: MatDialogConfig<D>,
): Observable<R | undefined> {
const ref = this.create<T, D, R>(templateOrComponentRef, config);
return ref.afterClosed();
}
如您所见,我删除了defer()
以匹配返回类型。由于一次只能打开一个对话框,所以应该可以。