如何解决可观察变量中的promise <void>等价是什么?
我正在使用有角度的打字机,并尝试从可观察对象返回承诺。
正确的方法是什么?
我尝试过:
of(EMPTY).toPromise() // error: Promise<Observable<never>>' is not assignable to type Promise<void>
of(null).toPromise() // no error but not sure if it is the right way
of().toPromise // error: Promise<Observable<unknown>>' is not assignable to type Promise<void>
更新:
//这是声明它的接口
export interface CustomStoreOptions extends StoreOptions<CustomStore> {
/** Specifies a custom implementation of the remove(key) method. */
remove?: ((key: any | string | number) => Promise<void> | JQueryPromise<void>);
}
因此它被称为:
let store = new CustomStore({
remove: key => {
// return ...
}
});
解决方法
您可以将其编写如下,以获得与Promise<void>
等效的内容
of(void(0))
您还可以创建一个不发出任何数据的主题
const s = new Subject<void>();
s.next(void(0));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。