加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – TypeScript模块扩充

发布时间:2020-12-17 17:24:12 所属栏目:安全 来源:网络整理
导读:我有可观察的扩展.它工作得很好,但现在我已经更新到角度为6的打字稿2.7.2. import { Observable } from 'rxjs/Observable';import { BaseComponent } from './base-component';import { Subscription } from 'rxjs/Subscription';import { Subscribable } fr
我有可观察的扩展.它工作得很好,但现在我已经更新到角度为6的打字稿2.7.2.

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>,complete?: () => void): Subscription {
    let sub = this.subscribe(next,error,complete);
    component.markForSafeDelete(sub);
    return sub;
}

Observable.prototype.safeSubscribe = safeSubscribe;

这段代码不起作用

>’Observable’仅指类型,但在此处用作值.
>’Observable’类型中不存在属性’subscribe’.

https://www.typescriptlang.org/docs/handbook/declaration-merging.html

解决方法

合并声明时,指定的模块路径必须与实际模块的路径完全匹配.

使用RxJS版本6,您将需要更改模块声明,因为内部结构已更改.从记忆中,它应该是:

declare module 'rxjs/internal/Observable' {
    export interface Observable<T> {
        safeSubscribe<T>(this: Observable<T>,complete?: () => void): Subscription;
    }
}

有关示例,请参阅rxjs-compat中的one of the patching imports.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读