ngZone的扩展方法

时间:2018-12-16 21:25:00

标签: angular typescript

我正在尝试在ngZone的TypeScript中创建扩展方法,但出现以下错误:

  

错误TS2484:导出声明​​与“ NgZone”的导出声明冲突。

扩展方法的代码段:

import { SchedulerLike, Subscription } from 'rxjs';
import { NgZone } from '@angular/core/src/zone';

declare module '@angular/core/src/zone' {
interface NgZone {
    enterZone(this: NgZone, scheduler: SchedulerLike): SchedulerLike;
}
}

class EnterZoneScheduler implements SchedulerLike {
constructor(private zone: NgZone, private scheduler: SchedulerLike) {}

schedule(...args: Array<any>): Subscription {
    return this.zone.run(() => this.scheduler.schedule.apply(this.scheduler, args));
}

now(): number {
    return this.scheduler.now();
}
}

function enterZone(this: NgZone, scheduler: SchedulerLike): SchedulerLike {
return new EnterZoneScheduler(this, scheduler);
}

NgZone.prototype.enterZone = enterZone;

你们中的任何人都可以告诉我为什么还是告诉我我做错了什么吗?

0 个答案:

没有答案