Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 610649b

Browse files
committed
fix: add better Type safety
1 parent 50b168a commit 610649b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: lib/zone.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -614,19 +614,21 @@ const Zone: ZoneType = (function(global: any) {
614614
return this._zoneDelegate.fork(this, zoneSpec);
615615
}
616616

617-
public wrap(callback: Function, source: string): Function {
617+
public wrap<T extends Function>(callback: T, source: string): T {
618618
if (typeof callback !== 'function') {
619619
throw new Error('Expecting function got: ' + callback);
620620
}
621621
const _callback = this._zoneDelegate.intercept(this, callback, source);
622622
const zone: Zone = this;
623623
return function() {
624624
return zone.runGuarded(_callback, this, <any>arguments, source);
625-
};
625+
} as any as T;
626626
}
627627

628-
public run(
629-
callback: Function, applyThis: any = null, applyArgs: any[] = null, source: string = null) {
628+
public run(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any;
629+
public run<T>(
630+
callback: (...args: any[]) => T, applyThis: any = null, applyArgs: any[] = null,
631+
source: string = null): T {
630632
_currentZoneFrame = new ZoneFrame(_currentZoneFrame, this);
631633
try {
632634
return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
@@ -635,8 +637,10 @@ const Zone: ZoneType = (function(global: any) {
635637
}
636638
}
637639

638-
public runGuarded(
639-
callback: Function, applyThis: any = null, applyArgs: any[] = null, source: string = null) {
640+
public runGuarded(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any;
641+
public runGuarded<T>(
642+
callback: (...args: any[]) => T, applyThis: any = null, applyArgs: any[] = null,
643+
source: string = null) {
640644
_currentZoneFrame = new ZoneFrame(_currentZoneFrame, this);
641645
try {
642646
try {
@@ -652,7 +656,7 @@ const Zone: ZoneType = (function(global: any) {
652656
}
653657

654658

655-
runTask(task: Task, applyThis?: any, applyArgs?: any) {
659+
runTask(task: Task, applyThis?: any, applyArgs?: any): any {
656660
task.runCount++;
657661
if (task.zone != this)
658662
throw new Error(

0 commit comments

Comments
 (0)