我有可观察的扩展。它工作得很好,但现在我已经用 typescript 2.7.2 更新到 angular 6。
import { Observable } from 'rxjs/Observable';
import { BaseComponent } from './base-component';
import { Subscription } from 'rxjs/Subscription';
import { Subscribable } from 'rxjs';
declare module 'rxjs/Observable' {
export interface Observable<T> {
safeSubscribe<T>(this: Observable<T>, component: BaseComponent,
next?: (value: T) => void, error?: (error: T) => void, complete?: () => void): Subscription;
}
}
export function safeSubscribe<T>(this: Observable<T>, component: BaseComponent,
next?: (value: T) => void, error?: (error: T) => void, complete?: () => void): Subscription {
let sub = this.subscribe(next, error, complete);
component.markForSafeDelete(sub);
return sub;
}
Observable.prototype.safeSubscribe = safeSubscribe;
而且这段代码不起作用
- 'Observable' 仅指一种类型,但在这里用作值。
- “可观察”类型上不存在属性“订阅”。
https://www.typescriptlang.org/docs/handbook/declaration-merging.html