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

Commit 54c8d35

Browse files
committed
feat(TypeScript): support TypeScript v2.2.1
1 parent ce47cfb commit 54c8d35

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

lib/zone.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ interface ZoneSpec {
410410
onHasTask?:
411411
(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) => void;
412412
}
413-
;
413+
414414

415415
/**
416416
* A delegate when intercepting zone operations.
@@ -463,13 +463,12 @@ type HasTaskState = {
463463
/**
464464
* Task type: `microTask`, `macroTask`, `eventTask`.
465465
*/
466-
type TaskType = string; /* TS v1.8 => "microTask" | "macroTask" | "eventTask" */
466+
type TaskType = 'microTask'|'macroTask'|'eventTask';
467467

468468
/**
469469
* Task type: `notScheduled`, `scheduling`, `scheduled`, `running`, `canceling`.
470470
*/
471-
type TaskState =
472-
string; /* TS v1.8 => "notScheduled", "scheduling", "scheduled", "running", "canceling" */
471+
type TaskState = 'notScheduled'|'scheduling'|'scheduled'|'running'|'canceling';
473472

474473

475474
/**
@@ -576,15 +575,15 @@ interface Task {
576575
}
577576

578577
interface MicroTask extends Task {
579-
/* TS v1.8 => type: 'microTask'; */
578+
type: 'microTask';
580579
}
581580

582581
interface MacroTask extends Task {
583-
/* TS v1.8 => type: 'macroTask'; */
582+
type: 'macroTask';
584583
}
585584

586585
interface EventTask extends Task {
587-
/* TS v1.8 => type: 'eventTask'; */
586+
type: 'eventTask';
588587
}
589588

590589
/**
@@ -613,9 +612,11 @@ const Zone: ZoneType = (function(global: any) {
613612
}
614613

615614
const NO_ZONE = {name: 'NO ZONE'};
616-
const notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled',
617-
running = 'running', canceling = 'canceling';
618-
const microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
615+
const notScheduled: 'notScheduled' = 'notScheduled', scheduling: 'scheduling' = 'scheduling',
616+
scheduled: 'scheduled' = 'scheduled', running: 'running' = 'running',
617+
canceling: 'canceling' = 'canceling';
618+
const microTask: 'microTask' = 'microTask', macroTask: 'macroTask' = 'macroTask',
619+
eventTask: 'eventTask' = 'eventTask';
619620

620621
class Zone implements AmbientZone {
621622
static __symbol__: (name: string) => string = __symbol__;
@@ -736,7 +737,7 @@ const Zone: ZoneType = (function(global: any) {
736737
'A task can only be run in the zone of creation! (Creation: ' +
737738
(task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
738739
const reEntryGuard = task.state != running;
739-
reEntryGuard && (task as ZoneTask)._transitionTo(running, scheduled);
740+
reEntryGuard && (task as ZoneTask<any>)._transitionTo(running, scheduled);
740741
task.runCount++;
741742
const previousTask = _currentTask;
742743
_currentTask = task;
@@ -757,30 +758,31 @@ const Zone: ZoneType = (function(global: any) {
757758
// if the task's state is notScheduled, then it has already been cancelled
758759
// we should not reset the state to scheduled
759760
if (task.state !== notScheduled) {
760-
reEntryGuard && (task as ZoneTask)._transitionTo(scheduled, running);
761+
reEntryGuard && (task as ZoneTask<any>)._transitionTo(scheduled, running);
761762
}
762763
} else {
763764
task.runCount = 0;
764-
this._updateTaskCount(task as ZoneTask, -1);
765-
reEntryGuard && (task as ZoneTask)._transitionTo(notScheduled, running, notScheduled);
765+
this._updateTaskCount(task as ZoneTask<any>, -1);
766+
reEntryGuard &&
767+
(task as ZoneTask<any>)._transitionTo(notScheduled, running, notScheduled);
766768
}
767769
_currentZoneFrame = _currentZoneFrame.parent;
768770
_currentTask = previousTask;
769771
}
770772
}
771773

772774
scheduleTask<T extends Task>(task: T): T {
773-
(task as any as ZoneTask)._transitionTo(scheduling, notScheduled);
775+
(task as any as ZoneTask<any>)._transitionTo(scheduling, notScheduled);
774776
const zoneDelegates: ZoneDelegate[] = [];
775-
(task as any as ZoneTask)._zoneDelegates = zoneDelegates;
777+
(task as any as ZoneTask<any>)._zoneDelegates = zoneDelegates;
776778
task.zone = this;
777779
task = this._zoneDelegate.scheduleTask(this, task) as T;
778-
if ((task as any as ZoneTask)._zoneDelegates === zoneDelegates) {
780+
if ((task as any as ZoneTask<any>)._zoneDelegates === zoneDelegates) {
779781
// we have to check because internally the delegate can reschedule the task.
780-
this._updateTaskCount(task as any as ZoneTask, 1);
782+
this._updateTaskCount(task as any as ZoneTask<any>, 1);
781783
}
782-
if ((task as any as ZoneTask).state == scheduling) {
783-
(task as any as ZoneTask)._transitionTo(scheduled, scheduling);
784+
if ((task as any as ZoneTask<any>).state == scheduling) {
785+
(task as any as ZoneTask<any>)._transitionTo(scheduled, scheduling);
784786
}
785787
return task;
786788
}
@@ -807,15 +809,15 @@ const Zone: ZoneType = (function(global: any) {
807809
}
808810

809811
cancelTask(task: Task): any {
810-
(task as ZoneTask)._transitionTo(canceling, scheduled, running);
812+
(task as ZoneTask<any>)._transitionTo(canceling, scheduled, running);
811813
this._zoneDelegate.cancelTask(this, task);
812-
this._updateTaskCount(task as ZoneTask, -1);
813-
(task as ZoneTask)._transitionTo(notScheduled, canceling);
814+
this._updateTaskCount(task as ZoneTask<any>, -1);
815+
(task as ZoneTask<any>)._transitionTo(notScheduled, canceling);
814816
task.runCount = 0;
815817
return task;
816818
}
817819

818-
private _updateTaskCount(task: ZoneTask, count: number) {
820+
private _updateTaskCount(task: ZoneTask<any>, count: number) {
819821
const zoneDelegates = task._zoneDelegates;
820822
if (count == -1) {
821823
task._zoneDelegates = null;
@@ -989,14 +991,14 @@ const Zone: ZoneType = (function(global: any) {
989991
}
990992

991993
scheduleTask(targetZone: Zone, task: Task): Task {
992-
let returnTask: ZoneTask = task as ZoneTask;
994+
let returnTask: ZoneTask<any> = task as ZoneTask<any>;
993995
if (this._scheduleTaskZS) {
994996
if (this._hasTaskZS) {
995997
returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
996998
}
997999
returnTask = this._scheduleTaskZS.onScheduleTask(
998-
this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task) as ZoneTask;
999-
if (!returnTask) returnTask = task as ZoneTask;
1000+
this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task) as ZoneTask<any>;
1001+
if (!returnTask) returnTask = task as ZoneTask<any>;
10001002
} else {
10011003
if (task.scheduleFn) {
10021004
task.scheduleFn(task);
@@ -1054,8 +1056,8 @@ const Zone: ZoneType = (function(global: any) {
10541056
}
10551057

10561058

1057-
class ZoneTask implements Task {
1058-
public type: TaskType;
1059+
class ZoneTask<T extends TaskType> implements Task {
1060+
public type: T;
10591061
public source: string;
10601062
public invoke: Function;
10611063
public callback: Function;
@@ -1068,7 +1070,7 @@ const Zone: ZoneType = (function(global: any) {
10681070
_state: TaskState = 'notScheduled';
10691071

10701072
constructor(
1071-
type: TaskType, source: string, callback: Function, options: TaskData,
1073+
type: T, source: string, callback: Function, options: TaskData,
10721074
scheduleFn: (task: Task) => void, cancelFn: (task: Task) => void) {
10731075
this.type = type;
10741076
this.source = source;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"ts-loader": "^0.6.0",
8080
"tslint": "^4.1.1",
8181
"tslint-eslint-rules": "^3.1.0",
82-
"typescript": "2.0.10",
82+
"typescript": "2.2.1",
8383
"vrsource-tslint-rules": "^4.0.0",
8484
"whatwg-fetch": "^2.0.1"
8585
}

test/common/microtasks.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,3 @@ describe('Microtasks', function() {
106106
});
107107
});
108108
});
109-
export let __something__;

test/common/zone.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {zoneSymbol} from '../../lib/common/utils';
10-
119
describe('Zone', function() {
1210
const rootZone = Zone.current;
1311

0 commit comments

Comments
 (0)