refactor: ensure zone.js can be built with typescript strict flag (#30993)
As part of FW-1265, the `zone.js` package is made compatible with the TypeScript `--strict` flag. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html) PR Close #30993
This commit is contained in:

committed by
Miško Hevery

parent
10a1e1974b
commit
60f58bf051
@ -115,7 +115,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
* This is ZoneAwareError which processes the stack frame and cleans up extra frames as well as
|
||||
* adds zone information to it.
|
||||
*/
|
||||
function ZoneAwareError(): Error {
|
||||
function ZoneAwareError(this: unknown | typeof NativeError): Error {
|
||||
// We always have to return native error otherwise the browser console will not work.
|
||||
let error: Error = NativeError.apply(this, arguments);
|
||||
// Save original stack trace
|
||||
|
@ -112,7 +112,7 @@ export function patchEventTarget(
|
||||
};
|
||||
|
||||
// global shared zoneAwareCallback to handle all event callback with capture = false
|
||||
const globalZoneAwareCallback = function(event: Event) {
|
||||
const globalZoneAwareCallback = function(this: unknown, event: Event) {
|
||||
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
|
||||
// event will be undefined, so we need to use window.event
|
||||
event = event || _global.event;
|
||||
@ -144,7 +144,7 @@ export function patchEventTarget(
|
||||
};
|
||||
|
||||
// global shared zoneAwareCallback to handle all event callback with capture = true
|
||||
const globalZoneAwareCaptureCallback = function(event: Event) {
|
||||
const globalZoneAwareCaptureCallback = function(this: unknown, event: Event) {
|
||||
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
|
||||
// event will be undefined, so we need to use window.event
|
||||
event = event || _global.event;
|
||||
@ -330,7 +330,7 @@ export function patchEventTarget(
|
||||
const makeAddListener = function(
|
||||
nativeListener: any, addSource: string, customScheduleFn: any, customCancelFn: any,
|
||||
returnTarget = false, prepend = false) {
|
||||
return function() {
|
||||
return function(this: unknown) {
|
||||
const target = this || _global;
|
||||
const eventName = arguments[0];
|
||||
let delegate = arguments[1];
|
||||
|
@ -54,7 +54,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
|
||||
|
||||
const UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
|
||||
|
||||
function handleUnhandledRejection(e: any) {
|
||||
function handleUnhandledRejection(this: unknown, e: any) {
|
||||
api.onUnhandledError(e);
|
||||
try {
|
||||
const handler = (Zone as any)[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
|
||||
@ -198,7 +198,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
|
||||
}
|
||||
|
||||
const REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
|
||||
function clearRejectedNoCatch(promise: ZoneAwarePromise<any>): void {
|
||||
function clearRejectedNoCatch(this: unknown, promise: ZoneAwarePromise<any>): void {
|
||||
if ((promise as any)[symbolState] === REJECTED_NO_CATCH) {
|
||||
// if the promise is rejected no catch status
|
||||
// and queue.length > 0, means there is a error handler
|
||||
@ -453,7 +453,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
|
||||
api.patchThen = patchThen;
|
||||
|
||||
function zoneify(fn: Function) {
|
||||
return function() {
|
||||
return function(this: unknown) {
|
||||
let resultPromise = fn.apply(this, arguments);
|
||||
if (resultPromise instanceof ZoneAwarePromise) {
|
||||
return resultPromise;
|
||||
|
@ -29,7 +29,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
|
||||
|
||||
function scheduleTask(task: Task) {
|
||||
const data = <TimerOptions>task.data;
|
||||
function timer() {
|
||||
function timer(this: unknown) {
|
||||
try {
|
||||
task.invoke.apply(this, arguments);
|
||||
} finally {
|
||||
|
@ -16,9 +16,9 @@ Zone.__load_patch('toString', (global: any) => {
|
||||
const ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
|
||||
const PROMISE_SYMBOL = zoneSymbol('Promise');
|
||||
const ERROR_SYMBOL = zoneSymbol('Error');
|
||||
const newFunctionToString = function toString() {
|
||||
const newFunctionToString = function toString(this: unknown) {
|
||||
if (typeof this === 'function') {
|
||||
const originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
|
||||
const originalDelegate = (this as any)[ORIGINAL_DELEGATE_SYMBOL];
|
||||
if (originalDelegate) {
|
||||
if (typeof originalDelegate === 'function') {
|
||||
return originalFunctionToString.call(originalDelegate);
|
||||
|
@ -80,7 +80,7 @@ export function patchPrototype(prototype: any, fnNames: string[]) {
|
||||
continue;
|
||||
}
|
||||
prototype[name] = ((delegate: Function) => {
|
||||
const patched: any = function() {
|
||||
const patched: any = function(this: unknown) {
|
||||
return delegate.apply(this, bindArguments(<any>arguments, source + '.' + name));
|
||||
};
|
||||
attachOriginToPatched(patched, delegate);
|
||||
@ -123,7 +123,7 @@ export const isMix: boolean = typeof _global.process !== 'undefined' &&
|
||||
|
||||
const zoneSymbolEventNames: {[eventName: string]: string} = {};
|
||||
|
||||
const wrapFn = function(event: Event) {
|
||||
const wrapFn = function(this: unknown, event: Event) {
|
||||
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
|
||||
// event will be undefined, so we need to use window.event
|
||||
event = event || _global.event;
|
||||
@ -197,7 +197,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
|
||||
eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
|
||||
}
|
||||
|
||||
desc.set = function(newValue) {
|
||||
desc.set = function(this: EventSource, newValue) {
|
||||
// in some of windows's onproperty callback, this is undefined
|
||||
// so we need to check it
|
||||
let target = this;
|
||||
@ -207,7 +207,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
let previousValue = target[eventNameSymbol];
|
||||
let previousValue = (target as any)[eventNameSymbol];
|
||||
if (previousValue) {
|
||||
target.removeEventListener(eventName, wrapFn);
|
||||
}
|
||||
@ -219,10 +219,10 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
|
||||
}
|
||||
|
||||
if (typeof newValue === 'function') {
|
||||
target[eventNameSymbol] = newValue;
|
||||
(target as any)[eventNameSymbol] = newValue;
|
||||
target.addEventListener(eventName, wrapFn, false);
|
||||
} else {
|
||||
target[eventNameSymbol] = null;
|
||||
(target as any)[eventNameSymbol] = null;
|
||||
}
|
||||
};
|
||||
|
||||
@ -238,7 +238,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
|
||||
if (!target) {
|
||||
return null;
|
||||
}
|
||||
const listener = target[eventNameSymbol];
|
||||
const listener = (target as any)[eventNameSymbol];
|
||||
if (listener) {
|
||||
return listener;
|
||||
} else if (originalDescGet) {
|
||||
@ -251,8 +251,8 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
|
||||
let value = originalDescGet && originalDescGet.call(this);
|
||||
if (value) {
|
||||
desc !.set !.call(this, value);
|
||||
if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
|
||||
target.removeAttribute(prop);
|
||||
if (typeof(target as any)[REMOVE_ATTRIBUTE] === 'function') {
|
||||
(target as any).removeAttribute(prop);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user