fix: migrate more files to strict-mode TypeScript (#7950)
This commit is contained in:
parent
f708ceb9f9
commit
aaac8d9c44
@ -43,7 +43,7 @@ export class TimeoutError extends CustomError {}
|
||||
*/
|
||||
export class ProtocolError extends CustomError {
|
||||
public code?: number;
|
||||
public originalMessage: string;
|
||||
public originalMessage = '';
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
|
@ -144,6 +144,6 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
}
|
||||
|
||||
private eventListenersCount(event: EventType): number {
|
||||
return this.eventsMap.has(event) ? this.eventsMap.get(event).length : 0;
|
||||
return this.eventsMap.get(event)?.length || 0;
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,9 @@ async function waitForEvent<T extends any>(
|
||||
timeout: number,
|
||||
abortPromise: Promise<Error>
|
||||
): Promise<T> {
|
||||
let eventTimeout, resolveCallback, rejectCallback;
|
||||
let eventTimeout: NodeJS.Timeout;
|
||||
let resolveCallback: (value: T | PromiseLike<T>) => void;
|
||||
let rejectCallback: (value: Error) => void;
|
||||
const promise = new Promise<T>((resolve, reject) => {
|
||||
resolveCallback = resolve;
|
||||
rejectCallback = reject;
|
||||
@ -192,7 +194,7 @@ function pageBindingInitString(type: string, name: string): string {
|
||||
const binding = win[bindingName];
|
||||
|
||||
win[bindingName] = (...args: unknown[]): Promise<unknown> => {
|
||||
const me = window[bindingName];
|
||||
const me = (window as any)[bindingName];
|
||||
let callbacks = me.callbacks;
|
||||
if (!callbacks) {
|
||||
callbacks = new Map();
|
||||
@ -216,8 +218,8 @@ function pageBindingDeliverResultString(
|
||||
result: unknown
|
||||
): string {
|
||||
function deliverResult(name: string, seq: number, result: unknown): void {
|
||||
window[name].callbacks.get(seq).resolve(result);
|
||||
window[name].callbacks.delete(seq);
|
||||
(window as any)[name].callbacks.get(seq).resolve(result);
|
||||
(window as any)[name].callbacks.delete(seq);
|
||||
}
|
||||
return evaluationString(deliverResult, name, seq, result);
|
||||
}
|
||||
@ -236,8 +238,8 @@ function pageBindingDeliverErrorString(
|
||||
): void {
|
||||
const error = new Error(message);
|
||||
error.stack = stack;
|
||||
window[name].callbacks.get(seq).reject(error);
|
||||
window[name].callbacks.delete(seq);
|
||||
(window as any)[name].callbacks.get(seq).reject(error);
|
||||
(window as any)[name].callbacks.delete(seq);
|
||||
}
|
||||
return evaluationString(deliverError, name, seq, message, stack);
|
||||
}
|
||||
@ -248,8 +250,8 @@ function pageBindingDeliverErrorValueString(
|
||||
value: unknown
|
||||
): string {
|
||||
function deliverErrorValue(name: string, seq: number, value: unknown): void {
|
||||
window[name].callbacks.get(seq).reject(value);
|
||||
window[name].callbacks.delete(seq);
|
||||
(window as any)[name].callbacks.get(seq).reject(value);
|
||||
(window as any)[name].callbacks.delete(seq);
|
||||
}
|
||||
return evaluationString(deliverErrorValue, name, seq, value);
|
||||
}
|
||||
@ -266,7 +268,9 @@ function makePredicateString(
|
||||
if (!node) return waitForHidden;
|
||||
if (!waitForVisible && !waitForHidden) return node;
|
||||
const element =
|
||||
node.nodeType === Node.TEXT_NODE ? node.parentElement : (node as Element);
|
||||
node.nodeType === Node.TEXT_NODE
|
||||
? (node.parentElement as Element)
|
||||
: (node as Element);
|
||||
|
||||
const style = window.getComputedStyle(element);
|
||||
const isVisible =
|
||||
@ -296,7 +300,7 @@ async function waitWithTimeout<T extends any>(
|
||||
taskName: string,
|
||||
timeout: number
|
||||
): Promise<T> {
|
||||
let reject;
|
||||
let reject: (reason?: Error) => void;
|
||||
const timeoutError = new TimeoutError(
|
||||
`waiting for ${taskName} failed: timeout ${timeout}ms exceeded`
|
||||
);
|
||||
@ -313,14 +317,14 @@ async function waitWithTimeout<T extends any>(
|
||||
async function getReadableAsBuffer(
|
||||
readable: Readable,
|
||||
path?: string
|
||||
): Promise<Buffer> {
|
||||
): Promise<Buffer | null> {
|
||||
if (!isNode && path) {
|
||||
throw new Error('Cannot write to a path outside of Node.js environment.');
|
||||
}
|
||||
|
||||
const fs = isNode ? await importFSModule() : null;
|
||||
|
||||
let fileHandle: import('fs').promises.FileHandle;
|
||||
let fileHandle: import('fs').promises.FileHandle | undefined;
|
||||
|
||||
if (path && fs) {
|
||||
fileHandle = await fs.promises.open(path, 'w');
|
||||
@ -328,12 +332,12 @@ async function getReadableAsBuffer(
|
||||
const buffers = [];
|
||||
for await (const chunk of readable) {
|
||||
buffers.push(chunk);
|
||||
if (fileHandle) {
|
||||
if (fileHandle && fs) {
|
||||
await fs.promises.writeFile(fileHandle, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if (path) await fileHandle.close();
|
||||
if (path && fileHandle) await fileHandle.close();
|
||||
let resultBuffer = null;
|
||||
try {
|
||||
resultBuffer = Buffer.concat(buffers);
|
||||
|
Loading…
Reference in New Issue
Block a user