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

Commit

Permalink
fix(tsc): tsconfig.json strict:true
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Jun 18, 2018
1 parent 1ba8519 commit 915042d
Show file tree
Hide file tree
Showing 47 changed files with 549 additions and 519 deletions.
22 changes: 8 additions & 14 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
if (!storedTask) {
target[XHR_TASK] = task;
}
sendNative.apply(target, data.args);
sendNative!.apply(target, data.args);
(XMLHttpRequest as any)[XHR_SCHEDULED] = true;
return task;
}
Expand All @@ -166,31 +166,25 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
// Note - ideally, we would call data.target.removeEventListener here, but it's too late
// to prevent it from firing. So instead, we store info for the event listener.
data.aborted = true;
return abortNative.apply(data.target, data.args);
return abortNative!.apply(data.target, data.args);
}

const openNative: Function =
const openNative =
patchMethod(XMLHttpRequestPrototype, 'open', () => function(self: any, args: any[]) {
self[XHR_SYNC] = args[2] == false;
self[XHR_URL] = args[1];
return openNative.apply(self, args);
return openNative!.apply(self, args);
});

const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
const sendNative: Function =
const sendNative =
patchMethod(XMLHttpRequestPrototype, 'send', () => function(self: any, args: any[]) {
if (self[XHR_SYNC]) {
// if the XHR is sync there is no task to schedule, just execute the code.
return sendNative.apply(self, args);
return sendNative!.apply(self, args);
} else {
const options: XHROptions = {
target: self,
url: self[XHR_URL],
isPeriodic: false,
delay: null,
args: args,
aborted: false
};
const options: XHROptions =
{target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false};
return scheduleMacroTaskWithCurrentZone(
XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function propertyPatch() {

Object.getOwnPropertyDescriptor = function(obj, prop) {
const desc = _getOwnPropertyDescriptor(obj, prop);
if (isUnconfigurable(obj, prop)) {
if (desc && isUnconfigurable(obj, prop)) {
desc.configurable = false;
}
return desc;
Expand Down Expand Up @@ -97,7 +97,7 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
try {
return _defineProperty(obj, prop, desc);
} catch (error) {
let descJson: string = null;
let descJson: string|null = null;
try {
descJson = JSON.stringify(desc);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/property-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function canPatchViaPropertyDescriptor() {
const detectFunc = () => {};
req.onreadystatechange = detectFunc;
const result = (req as any)[SYMBOL_FAKE_ONREADYSTATECHANGE] === detectFunc;
req.onreadystatechange = null;
req.onreadystatechange = null as any;
return result;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/common/error-rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
// Process the stack trace and rewrite the frames.
if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
let frames: string[] = originalStack.split('\n');
let zoneFrame = api.currentZoneFrame();
let zoneFrame: _ZoneFrame|null = api.currentZoneFrame();
let i = 0;
// Find the first frame
while (!(frames[i] === zoneAwareFrame1 || frames[i] === zoneAwareFrame2) &&
Expand Down Expand Up @@ -295,20 +295,20 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
() => {
throw new (ZoneAwareError as any)(ZoneAwareError, NativeError);
},
null,
undefined,
(t: Task) => {
(t as any)._transitionTo = fakeTransitionTo;
t.invoke();
});
},
null,
undefined,
(t) => {
(t as any)._transitionTo = fakeTransitionTo;
t.invoke();
},
() => {});
},
null,
undefined,
(t) => {
(t as any)._transitionTo = fakeTransitionTo;
t.invoke();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export function patchEventTarget(
taskData.eventName = eventName;
taskData.isExisting = isExisting;

const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null;
const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;

// keep taskData into data to allow onScheduleEventTask to access the task information
if (data) {
Expand Down
30 changes: 18 additions & 12 deletions lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
api.microtaskDrainDone = () => {
while (_uncaughtPromiseErrors.length) {
while (_uncaughtPromiseErrors.length) {
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift();
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift()!;
try {
uncaughtPromiseError.zone.runGuarded(() => {
throw uncaughtPromiseError;
Expand Down Expand Up @@ -164,7 +164,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
(promise as any)[symbolValue] = value;

if ((promise as any)[symbolFinally] === symbolFinally) {
// the promise is generated by Promise.prototype.finally
// the promise is generated by Promise.prototype.finally
if (state === RESOLVED) {
// the state is resolved, should ignore the value
// and use parent promise value
Expand Down Expand Up @@ -202,7 +202,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
error.rejection = value;
error.promise = promise;
error.zone = Zone.current;
error.task = Zone.currentTask;
error.task = Zone.currentTask!;
_uncaughtPromiseErrors.push(error);
api.scheduleMicroTask(); // to make sure that it is running
}
Expand Down Expand Up @@ -239,7 +239,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr

function scheduleResolveOrReject<R, U1, U2>(
promise: ZoneAwarePromise<any>, zone: AmbientZone, chainPromise: ZoneAwarePromise<any>,
onFulfilled?: (value: R) => U1, onRejected?: (error: any) => U2): void {
onFulfilled?: ((value: R) => U1) | null | undefined,
onRejected?: ((error: any) => U2) | null | undefined): void {
clearRejectedNoCatch(promise);
const promiseState = (promise as any)[symbolState];
const delegate = promiseState ?
Expand All @@ -248,14 +249,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
zone.scheduleMicroTask(source, () => {
try {
const parentPromiseValue = (promise as any)[symbolValue];
const isFinallyPromise = chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
const isFinallyPromise =
chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
if (isFinallyPromise) {
// if the promise is generated from finally call, keep parent promise's state and value
(chainPromise as any)[symbolParentPromiseValue] = parentPromiseValue;
(chainPromise as any)[symbolParentPromiseState] = promiseState;
}
// should not pass value to finally callback
const value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? [] : [parentPromiseValue]);
const value = zone.run(
delegate, undefined,
isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
[] :
[parentPromiseValue]);
resolvePromise(chainPromise, true, value);
} catch (error) {
// if error occurs, should always return this error
Expand All @@ -272,11 +278,11 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
}

static resolve<R>(value: R): Promise<R> {
return resolvePromise(<ZoneAwarePromise<R>>new this(null), RESOLVED, value);
return resolvePromise(<ZoneAwarePromise<R>>new this(null as any), RESOLVED, value);
}

static reject<U>(error: U): Promise<U> {
return resolvePromise(<ZoneAwarePromise<U>>new this(null), REJECTED, error);
return resolvePromise(<ZoneAwarePromise<U>>new this(null as any), REJECTED, error);
}

static race<R>(values: PromiseLike<any>[]): Promise<R> {
Expand Down Expand Up @@ -323,10 +329,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
resolve(resolvedValues);
}
})(count),
reject);
reject!);
count++;
}
if (!count) resolve(resolvedValues);
if (!count) resolve!(resolvedValues);
return promise;
}

Expand All @@ -351,7 +357,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>)|undefined|
null): Promise<TResult1|TResult2> {
const chainPromise: Promise<TResult1|TResult2> =
new (this.constructor as typeof ZoneAwarePromise)(null);
new (this.constructor as typeof ZoneAwarePromise)(null as any);
const zone = Zone.current;
if ((this as any)[symbolState] == UNRESOLVED) {
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
Expand All @@ -368,7 +374,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr

finally<U>(onFinally?: () => U | PromiseLike<U>): Promise<R> {
const chainPromise: Promise<R|never> =
new (this.constructor as typeof ZoneAwarePromise)(null);
new (this.constructor as typeof ZoneAwarePromise)(null as any);
(chainPromise as any)[symbolFinally] = symbolFinally;
const zone = Zone.current;
if ((this as any)[symbolState] == UNRESOLVED) {
Expand Down
16 changes: 8 additions & 8 deletions lib/common/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {patchMethod, scheduleMacroTaskWithCurrentZone, zoneSymbol} from './utils
const taskSymbol = zoneSymbol('zoneTask');

interface TimerOptions extends TaskData {
handleId: number;
handleId?: number;
args: any[];
}

export function patchTimer(window: any, setName: string, cancelName: string, nameSuffix: string) {
let setNative: Function = null;
let clearNative: Function = null;
let setNative: Function|null = null;
let clearNative: Function|null = null;
setName += nameSuffix;
cancelName += nameSuffix;

Expand Down Expand Up @@ -50,21 +50,21 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
}
}
data.args[0] = timer;
data.handleId = setNative.apply(window, data.args);
data.handleId = setNative!.apply(window, data.args);
return task;
}

function clearTask(task: Task) {
return clearNative((<TimerOptions>task.data).handleId);
return clearNative!((<TimerOptions>task.data).handleId);
}

setNative =
patchMethod(window, setName, (delegate: Function) => function(self: any, args: any[]) {
if (typeof args[0] === 'function') {
const options: TimerOptions = {
handleId: null,
isPeriodic: nameSuffix === 'Interval',
delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null,
delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
undefined,
args: args
};
const task =
Expand Down Expand Up @@ -118,7 +118,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
}
if (task && typeof task.type === 'string') {
if (task.state !== 'notScheduled' &&
(task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
(task.cancelFn && task.data!.isPeriodic || task.runCount === 0)) {
if (typeof id === 'number') {
delete tasksByHandleId[id];
} else if (id) {
Expand Down
25 changes: 12 additions & 13 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function wrapWithCurrentZone<T extends Function>(callback: T, source: str
}

export function scheduleMacroTaskWithCurrentZone(
source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void,
customCancel: (task: Task) => void): MacroTask {
source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void,
customCancel?: (task: Task) => void): MacroTask {
return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
// so we should use original native get to retrieve the handler
let value = originalDescGet && originalDescGet.call(this);
if (value) {
desc.set.call(this, value);
desc!.set!.call(this, value);
if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
target.removeAttribute(prop);
}
Expand All @@ -242,7 +242,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
ObjectDefineProperty(obj, prop, desc);
}

export function patchOnProperties(obj: any, properties: string[], prototype?: any) {
export function patchOnProperties(obj: any, properties: string[]|null, prototype?: any) {
if (properties) {
for (let i = 0; i < properties.length; i++) {
patchProperty(obj, 'on' + properties[i], prototype);
Expand Down Expand Up @@ -337,7 +337,7 @@ export function patchClass(className: string) {
export function patchMethod(
target: any, name: string,
patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) =>
any): Function {
any): Function|null {
let proto = target;
while (proto && !proto.hasOwnProperty(name)) {
proto = ObjectGetPrototypeOf(proto);
Expand All @@ -348,14 +348,14 @@ export function patchMethod(
}

const delegateName = zoneSymbol(name);
let delegate: Function;
let delegate: Function|null = null;
if (proto && !(delegate = proto[delegateName])) {
delegate = proto[delegateName] = proto[name];
// check whether proto[name] is writable
// some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
if (isPropertyWritable(desc)) {
const patchDelegate = patchFn(delegate, delegateName, name);
const patchDelegate = patchFn(delegate!, delegateName, name);
proto[name] = function() {
return patchDelegate(this, arguments as any);
};
Expand All @@ -375,22 +375,21 @@ export interface MacroTaskMeta extends TaskData {
// TODO: @JiaLiPassion, support cancel task later if necessary
export function patchMacroTask(
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MacroTaskMeta) {
let setNative: Function = null;
let setNative: Function|null = null;

function scheduleTask(task: Task) {
const data = <MacroTaskMeta>task.data;
data.args[data.cbIdx] = function() {
task.invoke.apply(this, arguments);
};
setNative.apply(data.target, data.args);
setNative!.apply(data.target, data.args);
return task;
}

setNative = patchMethod(obj, funcName, (delegate: Function) => function(self: any, args: any[]) {
const meta = metaCreator(self, args);
if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
return scheduleMacroTaskWithCurrentZone(
meta.name, args[meta.cbIdx], meta, scheduleTask, null);
return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
} else {
// cause an error by calling it directly.
return delegate.apply(self, args);
Expand All @@ -407,14 +406,14 @@ export interface MicroTaskMeta extends TaskData {

export function patchMicroTask(
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MicroTaskMeta) {
let setNative: Function = null;
let setNative: Function|null = null;

function scheduleTask(task: Task) {
const data = <MacroTaskMeta>task.data;
data.args[data.cbIdx] = function() {
task.invoke.apply(this, arguments);
};
setNative.apply(data.target, data.args);
setNative!.apply(data.target, data.args);
return task;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/extra/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
const SUCCESS_SOURCE = 'cordova.exec.success';
const ERROR_SOURCE = 'cordova.exec.error';
const FUNCTION = 'function';
const nativeExec: Function =
const nativeExec: Function|null =
api.patchMethod(global.cordova, 'exec', () => function(self: any, args: any[]) {
if (args.length > 0 && typeof args[0] === FUNCTION) {
args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE);
}
if (args.length > 1 && typeof args[1] === FUNCTION) {
args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
}
return nativeExec.apply(self, args);
return nativeExec!.apply(self, args);
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/extra/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('electron', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
function patchArguments(target: any, name: string, source: string): Function {
function patchArguments(target: any, name: string, source: string): Function|null {
return api.patchMethod(target, name, (delegate: Function) => (self: any, args: any[]) => {
return delegate && delegate.apply(self, api.bindArguments(args, source));
});
Expand Down
Loading

0 comments on commit 915042d

Please sign in to comment.