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

Commit d3c59d0

Browse files
committed
chore: make type checking stricter
1 parent 54c8d35 commit d3c59d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+431
-394
lines changed

lib/browser/browser.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {registerElementPatch} from './register-element';
1717
const set = 'set';
1818
const clear = 'clear';
1919
const blockingMethods = ['alert', 'prompt', 'confirm'];
20-
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;
20+
const _global: any =
21+
typeof window === 'object' && window || typeof self === 'object' && self || global;
2122

2223
patchTimer(_global, set, clear, 'Timeout');
2324
patchTimer(_global, set, clear, 'Interval');
@@ -64,7 +65,7 @@ function patchXHR(window: any) {
6465
}
6566

6667
function scheduleTask(task: Task) {
67-
self[XHR_SCHEDULED] = false;
68+
(XMLHttpRequest as any)[XHR_SCHEDULED] = false;
6869
const data = <XHROptions>task.data;
6970
// remove existing event listener
7071
const listener = data.target[XHR_LISTENER];
@@ -75,7 +76,7 @@ function patchXHR(window: any) {
7576
if (data.target.readyState === data.target.DONE) {
7677
// sometimes on some browsers XMLHttpRequest will fire onreadystatechange with
7778
// readyState=4 multiple times, so we need to check task state here
78-
if (!data.aborted && self[XHR_SCHEDULED] && task.state === 'scheduled') {
79+
if (!data.aborted && (XMLHttpRequest as any)[XHR_SCHEDULED] && task.state === 'scheduled') {
7980
task.invoke();
8081
}
8182
}
@@ -87,7 +88,7 @@ function patchXHR(window: any) {
8788
data.target[XHR_TASK] = task;
8889
}
8990
sendNative.apply(data.target, data.args);
90-
self[XHR_SCHEDULED] = true;
91+
(XMLHttpRequest as any)[XHR_SCHEDULED] = true;
9192
return task;
9293
}
9394

@@ -101,13 +102,13 @@ function patchXHR(window: any) {
101102
return abortNative.apply(data.target, data.args);
102103
}
103104

104-
const openNative =
105+
const openNative: Function =
105106
patchMethod(window.XMLHttpRequest.prototype, 'open', () => function(self: any, args: any[]) {
106107
self[XHR_SYNC] = args[2] == false;
107108
return openNative.apply(self, args);
108109
});
109110

110-
const sendNative =
111+
const sendNative: Function =
111112
patchMethod(window.XMLHttpRequest.prototype, 'send', () => function(self: any, args: any[]) {
112113
const zone = Zone.current;
113114
if (self[XHR_SYNC]) {
@@ -162,8 +163,9 @@ function findPromiseRejectionHandler(evtName: string) {
162163
}
163164

164165
if (_global['PromiseRejectionEvent']) {
165-
Zone[zoneSymbol('unhandledPromiseRejectionHandler')] =
166+
(Zone as any)[zoneSymbol('unhandledPromiseRejectionHandler')] =
166167
findPromiseRejectionHandler('unhandledrejection');
167168

168-
Zone[zoneSymbol('rejectionHandledHandler')] = findPromiseRejectionHandler('rejectionhandled');
169+
(Zone as any)[zoneSymbol('rejectionHandledHandler')] =
170+
findPromiseRejectionHandler('rejectionhandled');
169171
}

lib/browser/define-property.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {zoneSymbol} from '../common/utils';
1212
* things like redefining `createdCallback` on an element.
1313
*/
1414

15-
const _defineProperty = Object[zoneSymbol('defineProperty')] = Object.defineProperty;
16-
const _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] =
15+
const _defineProperty = (Object as any)[zoneSymbol('defineProperty')] = Object.defineProperty;
16+
const _getOwnPropertyDescriptor = (Object as any)[zoneSymbol('getOwnPropertyDescriptor')] =
1717
Object.getOwnPropertyDescriptor;
1818
const _create = Object.create;
1919
const unconfigurablesKey = zoneSymbol('unconfigurables');
@@ -37,7 +37,7 @@ export function propertyPatch() {
3737
return obj;
3838
};
3939

40-
Object.create = <any>function(obj, proto) {
40+
Object.create = <any>function(obj: any, proto: any) {
4141
if (typeof proto === 'object' && !Object.isFrozen(proto)) {
4242
Object.keys(proto).forEach(function(prop) {
4343
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
@@ -55,17 +55,17 @@ export function propertyPatch() {
5555
};
5656
};
5757

58-
export function _redefineProperty(obj, prop, desc) {
58+
export function _redefineProperty(obj: any, prop: string, desc: any) {
5959
const originalConfigurableFlag = desc.configurable;
6060
desc = rewriteDescriptor(obj, prop, desc);
6161
return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
6262
};
6363

64-
function isUnconfigurable(obj, prop) {
64+
function isUnconfigurable(obj: any, prop: any) {
6565
return obj && obj[unconfigurablesKey] && obj[unconfigurablesKey][prop];
6666
}
6767

68-
function rewriteDescriptor(obj, prop, desc) {
68+
function rewriteDescriptor(obj: any, prop: string, desc: any) {
6969
desc.configurable = true;
7070
if (!desc.configurable) {
7171
if (!obj[unconfigurablesKey]) {
@@ -76,7 +76,7 @@ function rewriteDescriptor(obj, prop, desc) {
7676
return desc;
7777
}
7878

79-
function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) {
79+
function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigurableFlag: any) {
8080
try {
8181
return _defineProperty(obj, prop, desc);
8282
} catch (error) {

lib/browser/event-target.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const NO_EVENT_TARGET =
1515
.split(',');
1616
const EVENT_TARGET = 'EventTarget';
1717

18-
export function eventTargetPatch(_global) {
18+
export function eventTargetPatch(_global: any) {
1919
let apis = [];
2020
const isWtf = _global['wtf'];
2121
if (isWtf) {

lib/browser/property-descriptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const eventNames =
1414
'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror'
1515
.split(' ');
1616

17-
export function propertyDescriptorPatch(_global) {
17+
export function propertyDescriptorPatch(_global: any) {
1818
if (isNode && !isMix) {
1919
return;
2020
}
@@ -86,7 +86,7 @@ function patchViaCapturingAllTheEvents() {
8686
const property = eventNames[i];
8787
const onproperty = 'on' + property;
8888
self.addEventListener(property, function(event) {
89-
let elt = <Node>event.target, bound, source;
89+
let elt: any = <Node>event.target, bound, source;
9090
if (elt) {
9191
source = elt.constructor['name'] + '.' + onproperty;
9292
} else {

lib/browser/register-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function registerElementPatch(_global: any) {
1919
const callbacks =
2020
['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
2121

22-
(<any>document).registerElement = function(name, opts) {
22+
(<any>document).registerElement = function(name: any, opts: any) {
2323
if (opts && opts.prototype) {
2424
callbacks.forEach(function(callback) {
2525
const source = 'Document.registerElement::' + callback;

lib/browser/webapis-media-query.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@
1313
if (!_global['MediaQueryList']) {
1414
return;
1515
}
16-
const patchEventTargetMethods = Zone[Zone['__symbol__']('patchEventTargetMethods')];
16+
const patchEventTargetMethods =
17+
(Zone as any)[(Zone as any)['__symbol__']('patchEventTargetMethods')];
1718
patchEventTargetMethods(
18-
_global['MediaQueryList'].prototype, 'addListener', 'removeListener', (self, args) => {
19+
_global['MediaQueryList'].prototype, 'addListener', 'removeListener',
20+
(self: any, args: any[]) => {
1921
return {
2022
useCapturing: false,
2123
eventName: 'mediaQuery',
2224
handler: args[0],
2325
target: self || _global,
2426
name: 'mediaQuery',
25-
invokeAddFunc: function(addFnSymbol: any, delegate) {
27+
invokeAddFunc: function(addFnSymbol: any, delegate: any) {
2628
if (delegate && (<Task>delegate).invoke) {
2729
return this.target[addFnSymbol]((<Task>delegate).invoke);
2830
} else {
2931
return this.target[addFnSymbol](delegate);
3032
}
3133
},
32-
invokeRemoveFunc: function(removeFnSymbol: any, delegate) {
34+
invokeRemoveFunc: function(removeFnSymbol: any, delegate: any) {
3335
if (delegate && (<Task>delegate).invoke) {
3436
return this.target[removeFnSymbol]((<Task>delegate).invoke);
3537
} else {

lib/browser/webapis-notification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
if (!desc || !desc.configurable) {
1919
return;
2020
}
21-
const patchOnProperties = Zone[Zone['__symbol__']('patchOnProperties')];
21+
const patchOnProperties = (Zone as any)[(Zone as any)['__symbol__']('patchOnProperties')];
2222
patchOnProperties(Notification.prototype, null);
2323
}
2424
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

lib/browser/websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function apply(_global: any) {
1616
if (!(<any>_global).EventTarget) {
1717
patchEventTargetMethods(WS.prototype);
1818
}
19-
(<any>_global).WebSocket = function(a, b) {
19+
(<any>_global).WebSocket = function(a: any, b: any) {
2020
const socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
21-
let proxySocket;
21+
let proxySocket: any;
2222

2323
// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
2424
const onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');

lib/common/timers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ interface TimerOptions extends TaskData {
1414
}
1515

1616
export function patchTimer(window: any, setName: string, cancelName: string, nameSuffix: string) {
17-
let setNative = null;
18-
let clearNative = null;
17+
let setNative: Function = null;
18+
let clearNative: Function = null;
1919
setName += nameSuffix;
2020
cancelName += nameSuffix;
2121

lib/common/utils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313

1414
// Hack since TypeScript isn't compiling this for a worker.
15-
declare const WorkerGlobalScope;
15+
declare const WorkerGlobalScope: any;
16+
declare const window: any;
17+
1618
export const zoneSymbol: (name: string) => string = (n) => `__zone_symbol__${n}`;
1719
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;
1820

@@ -25,7 +27,7 @@ export function bindArguments(args: any[], source: string): any[] {
2527
return args;
2628
}
2729

28-
export function patchPrototype(prototype, fnNames) {
30+
export function patchPrototype(prototype: any, fnNames: string[]) {
2931
const source = prototype.constructor['name'];
3032
for (let i = 0; i < fnNames.length; i++) {
3133
const name = fnNames[i];
@@ -55,7 +57,7 @@ export const isMix: boolean = typeof process !== 'undefined' &&
5557
{}.toString.call(process) === '[object process]' && !isWebWorker &&
5658
!!(typeof window !== 'undefined' && window['HTMLElement']);
5759

58-
export function patchProperty(obj, prop) {
60+
export function patchProperty(obj: any, prop: string) {
5961
const desc = Object.getOwnPropertyDescriptor(obj, prop) || {enumerable: true, configurable: true};
6062

6163
const originalDesc = Object.getOwnPropertyDescriptor(obj, 'original' + prop);
@@ -82,7 +84,7 @@ export function patchProperty(obj, prop) {
8284
}
8385

8486
if (typeof fn === 'function') {
85-
const wrapFn = function(event) {
87+
const wrapFn = function(event: Event) {
8688
let result;
8789
result = fn.apply(this, arguments);
8890

@@ -365,8 +367,8 @@ export function makeZoneAwareListeners(fnName: string) {
365367
return [];
366368
}
367369
return target[EVENT_TASKS]
368-
.filter(task => task.data.eventName === eventName)
369-
.map(task => task.data.handler);
370+
.filter((task: Task) => (task.data as any)['eventName'] === eventName)
371+
.map((task: Task) => (task.data as any)['handler']);
370372
};
371373
}
372374

@@ -393,7 +395,7 @@ export function patchEventTargetMethods(
393395
const originalInstanceKey = zoneSymbol('originalInstance');
394396

395397
// wrap some native API on `window`
396-
export function patchClass(className) {
398+
export function patchClass(className: string) {
397399
const OriginalClass = _global[className];
398400
if (!OriginalClass) return;
399401

@@ -497,7 +499,7 @@ export interface MacroTaskMeta extends TaskData {
497499
// TODO: @JiaLiPassion, support cancel task later if necessary
498500
export function patchMacroTask(
499501
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MacroTaskMeta) {
500-
let setNative = null;
502+
let setNative: Function = null;
501503

502504
function scheduleTask(task: Task) {
503505
const data = <MacroTaskMeta>task.data;
@@ -530,7 +532,7 @@ export interface MicroTaskMeta extends TaskData {
530532

531533
export function patchMicroTask(
532534
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MicroTaskMeta) {
533-
let setNative = null;
535+
let setNative: Function = null;
534536

535537
function scheduleTask(task: Task) {
536538
const data = <MacroTaskMeta>task.data;
@@ -570,5 +572,5 @@ export function findEventTask(target: any, evtName: string): Task[] {
570572
return result;
571573
}
572574

573-
Zone[zoneSymbol('patchEventTargetMethods')] = patchEventTargetMethods;
574-
Zone[zoneSymbol('patchOnProperties')] = patchOnProperties;
575+
(Zone as any)[zoneSymbol('patchEventTargetMethods')] = patchEventTargetMethods;
576+
(Zone as any)[zoneSymbol('patchOnProperties')] = patchOnProperties;

lib/extra/bluebird.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
((_global: any) => {
9-
const __symbol__ = Zone['__symbol__'];
9+
const __symbol__ = (Zone as any)['__symbol__'];
1010
// TODO: @JiaLiPassion, we can automatically patch bluebird
1111
// if global.Promise = Bluebird, but sometimes in nodejs,
1212
// global.Promise is not Bluebird, and Bluebird is just be
1313
// used by other libraries such as sequelize, so I think it is
1414
// safe to just expose a method to patch Bluebird explicitly
15-
Zone[__symbol__('bluebird')] = function patchBluebird(Bluebird) {
16-
Bluebird.setScheduler((fn) => {
15+
(Zone as any)[__symbol__('bluebird')] = function patchBluebird(Bluebird: any) {
16+
Bluebird.setScheduler((fn: Function) => {
1717
Zone.current.scheduleMicroTask('bluebird', fn);
1818
});
1919
};

lib/jasmine/jasmine.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
'use strict';
1010
(() => {
11-
const __extends = function(d, b) {
11+
const __extends = function(d: any, b: any) {
1212
for (const p in b)
1313
if (b.hasOwnProperty(p)) d[p] = b[p];
1414
function __() {
1515
this.constructor = d;
1616
}
17-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new (__ as any)());
1818
};
1919
// Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
2020
// in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503)
2121
if (!Zone) throw new Error('Missing: zone.js');
2222
if (typeof jasmine == 'undefined') throw new Error('Missing: jasmine.js');
23-
if (jasmine['__zone_patch__'])
23+
if ((jasmine as any)['__zone_patch__'])
2424
throw new Error('\'jasmine\' has already been patched with \'Zone\'.');
25-
jasmine['__zone_patch__'] = true;
25+
(jasmine as any)['__zone_patch__'] = true;
2626

27-
const SyncTestZoneSpec: {new (name: string): ZoneSpec} = Zone['SyncTestZoneSpec'];
28-
const ProxyZoneSpec: {new (): ZoneSpec} = Zone['ProxyZoneSpec'];
27+
const SyncTestZoneSpec: {new (name: string): ZoneSpec} = (Zone as any)['SyncTestZoneSpec'];
28+
const ProxyZoneSpec: {new (): ZoneSpec} = (Zone as any)['ProxyZoneSpec'];
2929
if (!SyncTestZoneSpec) throw new Error('Missing: SyncTestZoneSpec');
3030
if (!ProxyZoneSpec) throw new Error('Missing: ProxyZoneSpec');
3131

@@ -47,7 +47,7 @@
4747
let testProxyZone: Zone = null;
4848

4949
// Monkey patch all of the jasmine DSL so that each function runs in appropriate zone.
50-
const jasmineEnv = jasmine.getEnv();
50+
const jasmineEnv: any = jasmine.getEnv();
5151
['describe', 'xdescribe', 'fdescribe'].forEach((methodName) => {
5252
let originalJasmineFn: Function = jasmineEnv[methodName];
5353
jasmineEnv[methodName] = function(description: string, specDefinitions: Function) {
@@ -89,7 +89,7 @@
8989
// The `done` callback is only passed through if the function expects at least one argument.
9090
// Note we have to make a function with correct number of arguments, otherwise jasmine will
9191
// think that all functions are sync or async.
92-
return testBody && (testBody.length ? function(done) {
92+
return testBody && (testBody.length ? function(done: Function) {
9393
return testProxyZone.run(testBody, this, [done]);
9494
} : function() {
9595
return testProxyZone.run(testBody, this);
@@ -101,8 +101,8 @@
101101
interface QueueRunnerAttrs {
102102
queueableFns: {fn: Function}[];
103103
onComplete: () => void;
104-
clearStack: (fn) => void;
105-
onException: (error) => void;
104+
clearStack: (fn: any) => void;
105+
onException: (error: any) => void;
106106
catchException: () => boolean;
107107
userContext: any;
108108
timeout: {setTimeout: Function, clearTimeout: Function};
@@ -112,7 +112,7 @@
112112
const QueueRunner = (jasmine as any).QueueRunner as {new (attrs: QueueRunnerAttrs): QueueRunner};
113113
(jasmine as any).QueueRunner = (function(_super) {
114114
__extends(ZoneQueueRunner, _super);
115-
function ZoneQueueRunner(attrs) {
115+
function ZoneQueueRunner(attrs: {onComplete: Function}) {
116116
attrs.onComplete = ((fn) => () => {
117117
// All functions are done, clear the test zone.
118118
testProxyZone = null;

0 commit comments

Comments
 (0)