From 6e0964c8dff48691f7155d12096e777a8f9389f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 17 May 2021 23:48:49 +0200 Subject: [PATCH] Prepare code for strict type checking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 7 +- src/charging-station/Bootstrap.ts | 10 +-- src/charging-station/ChargingStation.ts | 78 +++++++++---------- src/charging-station/StationWorker.ts | 2 +- .../ocpp/1.6/OCCP16IncomingRequestService.ts | 2 +- .../ocpp/OCPPRequestService.ts | 4 +- src/types/ocpp/Requests.ts | 2 +- src/utils/Configuration.ts | 4 +- src/utils/Utils.ts | 20 ++--- src/worker/WorkerAbstract.ts | 2 +- src/worker/WorkerDynamicPool.ts | 6 +- src/worker/WorkerFactory.ts | 2 +- src/worker/WorkerSet.ts | 2 +- src/worker/WorkerStaticPool.ts | 6 +- tsconfig.json | 4 +- 15 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index a1e55989..0562a897 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -9,7 +9,7 @@ import logger from '../utils/Logger'; export default class AutomaticTransactionGenerator { public timeToStop: boolean; private chargingStation: ChargingStation; - private performanceObserver: PerformanceObserver; + private performanceObserver!: PerformanceObserver; constructor(chargingStation: ChargingStation) { this.chargingStation = chargingStation; @@ -149,10 +149,11 @@ export default class AutomaticTransactionGenerator { // eslint-disable-next-line consistent-this private async stopTransaction(connectorId: number, self: AutomaticTransactionGenerator): Promise { const transactionId = self.chargingStation.getConnector(connectorId).transactionId; - return await self.chargingStation.ocppRequestService.sendStopTransaction(transactionId, self.chargingStation.getTransactionMeterStop(transactionId), self.chargingStation.getTransactionIdTag(transactionId)); + return await self.chargingStation.ocppRequestService.sendStopTransaction(transactionId, self.chargingStation.getTransactionMeterStop(transactionId), + self.chargingStation.getTransactionIdTag(transactionId)); } - private logPrefix(connectorId: number = null): string { + private logPrefix(connectorId?: number): string { if (connectorId) { return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' | ATG on connector #' + connectorId.toString() + ':'); } diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index d6ebd549..a6eb4939 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -10,7 +10,7 @@ export default class Bootstrap { private static instance: Bootstrap; private started: boolean; private workerScript: string; - private workerImplementationInstance: WorkerAbstract; + private workerImplementationInstance: WorkerAbstract | null = null; private constructor() { this.started = false; @@ -29,7 +29,7 @@ export default class Bootstrap { if (isMainThread && !this.started) { try { let numStationsTotal = 0; - await this.getWorkerImplementationInstance().start(); + await this.getWorkerImplementationInstance()?.start(); // Start ChargingStation object in worker thread if (Configuration.getStationTemplateURLs()) { for (const stationURL of Configuration.getStationTemplateURLs()) { @@ -40,7 +40,7 @@ export default class Bootstrap { index, templateFile: path.join(path.resolve(__dirname, '../'), 'assets', 'station-templates', path.basename(stationURL.file)) }; - await this.getWorkerImplementationInstance().addElement(workerData); + await this.getWorkerImplementationInstance()?.addElement(workerData); numStationsTotal++; } } catch (error) { @@ -64,7 +64,7 @@ export default class Bootstrap { public async stop(): Promise { if (isMainThread && this.started) { - await this.getWorkerImplementationInstance().stop(); + await this.getWorkerImplementationInstance()?.stop(); // Nullify to force worker implementation instance creation this.workerImplementationInstance = null; } @@ -76,7 +76,7 @@ export default class Bootstrap { await this.start(); } - private getWorkerImplementationInstance(): WorkerAbstract { + private getWorkerImplementationInstance(): WorkerAbstract | null { if (!this.workerImplementationInstance) { this.workerImplementationInstance = WorkerFactory.getWorkerImplementation(this.workerScript, Configuration.getWorkerProcess(), { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d1745f75..ff912e97 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -34,28 +34,28 @@ import path from 'path'; export default class ChargingStation { public stationTemplateFile: string; public authorizedTags: string[]; - public stationInfo: ChargingStationInfo; + public stationInfo!: ChargingStationInfo; public connectors: Connectors; - public configuration: ChargingStationConfiguration; + public configuration!: ChargingStationConfiguration; public hasStopped: boolean; - public wsConnection: WebSocket; + public wsConnection!: WebSocket; public requests: Requests; public messageQueue: string[]; - public performanceStatistics: PerformanceStatistics; - public heartbeatSetInterval: NodeJS.Timeout; - public ocppIncomingRequestService: OCPPIncomingRequestService; - public ocppRequestService: OCPPRequestService; + public performanceStatistics!: PerformanceStatistics; + public heartbeatSetInterval!: NodeJS.Timeout; + public ocppIncomingRequestService!: OCPPIncomingRequestService; + public ocppRequestService!: OCPPRequestService; private index: number; - private bootNotificationRequest: BootNotificationRequest; - private bootNotificationResponse: BootNotificationResponse; - private connectorsConfigurationHash: string; - private supervisionUrl: string; - private wsConnectionUrl: string; + private bootNotificationRequest!: BootNotificationRequest; + private bootNotificationResponse!: BootNotificationResponse | null; + private connectorsConfigurationHash!: string; + private supervisionUrl!: string; + private wsConnectionUrl!: string; private hasSocketRestarted: boolean; private autoReconnectRetryCount: number; - private automaticTransactionGeneration: AutomaticTransactionGenerator; - private performanceObserver: PerformanceObserver; - private webSocketPingSetInterval: NodeJS.Timeout; + private automaticTransactionGeneration!: AutomaticTransactionGenerator; + private performanceObserver!: PerformanceObserver; + private webSocketPingSetInterval!: NodeJS.Timeout; constructor(index: number, stationTemplateFile: string) { this.index = index; @@ -86,11 +86,11 @@ export default class ChargingStation { return !Utils.isEmptyArray(this.authorizedTags); } - public getEnableStatistics(): boolean { + public getEnableStatistics(): boolean | undefined { return !Utils.isUndefined(this.stationInfo.enableStatistics) ? this.stationInfo.enableStatistics : true; } - public getNumberOfPhases(): number { + public getNumberOfPhases(): number | undefined { switch (this.getCurrentOutType()) { case CurrentOutType.AC: return !Utils.isUndefined(this.stationInfo.numberOfPhases) ? this.stationInfo.numberOfPhases : 3; @@ -119,11 +119,11 @@ export default class ChargingStation { return this.connectors[id]; } - public getCurrentOutType(): CurrentOutType { + public getCurrentOutType(): CurrentOutType | undefined { return !Utils.isUndefined(this.stationInfo.currentOutType) ? this.stationInfo.currentOutType : CurrentOutType.AC; } - public getVoltageOut(): number { + public getVoltageOut(): number | undefined { const errMsg = `${this.logPrefix()} Unknown ${this.getCurrentOutType()} currentOutType in template file ${this.stationTemplateFile}, cannot define default voltage out`; let defaultVoltageOut: number; switch (this.getCurrentOutType()) { @@ -140,7 +140,7 @@ export default class ChargingStation { return !Utils.isUndefined(this.stationInfo.voltageOut) ? this.stationInfo.voltageOut : defaultVoltageOut; } - public getTransactionIdTag(transactionId: number): string { + public getTransactionIdTag(transactionId: number): string | undefined { for (const connector in this.connectors) { if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { return this.getConnector(Utils.convertToInt(connector)).idTag; @@ -148,7 +148,7 @@ export default class ChargingStation { } } - public getTransactionMeterStop(transactionId: number): number { + public getTransactionMeterStop(transactionId: number): number | undefined { for (const connector in this.connectors) { if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { return this.getConnector(Utils.convertToInt(connector)).lastEnergyActiveImportRegisterValue; @@ -264,8 +264,8 @@ export default class ChargingStation { this.hasStopped = true; } - public getConfigurationKey(key: string | StandardParametersKey, caseInsensitive = false): ConfigurationKey { - const configurationKey: ConfigurationKey = this.configuration.configurationKey.find((configElement) => { + public getConfigurationKey(key: string | StandardParametersKey, caseInsensitive = false): ConfigurationKey | undefined { + const configurationKey: ConfigurationKey | undefined = this.configuration.configurationKey.find((configElement) => { if (caseInsensitive) { return configElement.key.toLowerCase() === key.toLowerCase(); } @@ -301,7 +301,7 @@ export default class ChargingStation { public setChargingProfile(connectorId: number, cp: ChargingProfile): boolean { if (!Utils.isEmptyArray(this.getConnector(connectorId).chargingProfiles)) { - this.getConnector(connectorId).chargingProfiles.forEach((chargingProfile: ChargingProfile, index: number) => { + this.getConnector(connectorId).chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => { if (chargingProfile.chargingProfileId === cp.chargingProfileId || (chargingProfile.stackLevel === cp.stackLevel && chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)) { this.getConnector(connectorId).chargingProfiles[index] = cp; @@ -309,7 +309,7 @@ export default class ChargingStation { } }); } - this.getConnector(connectorId).chargingProfiles.push(cp); + this.getConnector(connectorId).chargingProfiles?.push(cp); return true; } @@ -501,7 +501,7 @@ export default class ChargingStation { this.hasSocketRestarted = false; } - private async onClose(closeEvent): Promise { + private async onClose(closeEvent: any): Promise { switch (closeEvent) { case WebSocketCloseEventStatusCode.CLOSE_NORMAL: // Normal close case WebSocketCloseEventStatusCode.CLOSE_NO_STATUS: @@ -586,7 +586,7 @@ export default class ChargingStation { logger.debug(this.logPrefix() + ' Has received a WS pong (rfc6455) from the server'); } - private async onError(errorEvent): Promise { + private async onError(errorEvent: any): Promise { logger.error(this.logPrefix() + ' Socket error: %j', errorEvent); // pragma switch (errorEvent.code) { // case 'ECONNREFUSED': @@ -599,7 +599,7 @@ export default class ChargingStation { return this.stationInfo.Configuration ? this.stationInfo.Configuration : {} as ChargingStationConfiguration; } - private getAuthorizationFile(): string { + private getAuthorizationFile(): string | undefined { return this.stationInfo.authorizationFile && path.join(path.resolve(__dirname, '../'), 'assets', path.basename(this.stationInfo.authorizationFile)); } @@ -622,7 +622,7 @@ export default class ChargingStation { return authorizedTags; } - private getUseConnectorId0(): boolean { + private getUseConnectorId0(): boolean | undefined { return !Utils.isUndefined(this.stationInfo.useConnectorId0) ? this.stationInfo.useConnectorId0 : true; } @@ -637,7 +637,7 @@ export default class ChargingStation { } // 0 for disabling - private getConnectionTimeout(): number { + private getConnectionTimeout(): number | undefined { if (!Utils.isUndefined(this.stationInfo.connectionTimeout)) { return this.stationInfo.connectionTimeout; } @@ -648,7 +648,7 @@ export default class ChargingStation { } // -1 for unlimited, 0 for disabling - private getAutoReconnectMaxRetries(): number { + private getAutoReconnectMaxRetries(): number | undefined { if (!Utils.isUndefined(this.stationInfo.autoReconnectMaxRetries)) { return this.stationInfo.autoReconnectMaxRetries; } @@ -659,7 +659,7 @@ export default class ChargingStation { } // 0 for disabling - private getRegistrationMaxRetries(): number { + private getRegistrationMaxRetries(): number | undefined { if (!Utils.isUndefined(this.stationInfo.registrationMaxRetries)) { return this.stationInfo.registrationMaxRetries; } @@ -776,7 +776,6 @@ export default class ChargingStation { private stopWebSocketPing(): void { if (this.webSocketPingSetInterval) { clearInterval(this.webSocketPingSetInterval); - this.webSocketPingSetInterval = null; } } @@ -795,7 +794,7 @@ export default class ChargingStation { return supervisionUrls as string; } - private getHeartbeatInterval(): number { + private getHeartbeatInterval(): number | undefined { const HeartbeatInterval = this.getConfigurationKey(StandardParametersKey.HeartbeatInterval); if (HeartbeatInterval) { return Utils.convertToInt(HeartbeatInterval.value) * 1000; @@ -809,7 +808,6 @@ export default class ChargingStation { private stopHeartbeat(): void { if (this.heartbeatSetInterval) { clearInterval(this.heartbeatSetInterval); - this.heartbeatSetInterval = null; } } @@ -817,7 +815,7 @@ export default class ChargingStation { if (Utils.isUndefined(options)) { options = {} as WebSocket.ClientOptions; } - if (Utils.isUndefined(options.handshakeTimeout)) { + if (Utils.isUndefined(options?.handshakeTimeout)) { options.handshakeTimeout = this.getConnectionTimeout() * 1000; } if (this.isWebSocketOpen() && forceCloseOpened) { @@ -877,11 +875,11 @@ export default class ChargingStation { }); } - private getReconnectExponentialDelay(): boolean { + private getReconnectExponentialDelay(): boolean | undefined { return !Utils.isUndefined(this.stationInfo.reconnectExponentialDelay) ? this.stationInfo.reconnectExponentialDelay : false; } - private async reconnect(error): Promise { + private async reconnect(error: any): Promise { // Stop heartbeat this.stopHeartbeat(); // Stop the ATG if needed @@ -906,8 +904,8 @@ export default class ChargingStation { private initTransactionOnConnector(connectorId: number): void { this.getConnector(connectorId).transactionStarted = false; - this.getConnector(connectorId).transactionId = null; - this.getConnector(connectorId).idTag = null; + delete this.getConnector(connectorId).transactionId; + delete this.getConnector(connectorId).idTag; this.getConnector(connectorId).lastEnergyActiveImportRegisterValue = -1; } } diff --git a/src/charging-station/StationWorker.ts b/src/charging-station/StationWorker.ts index 84cb023b..5977b8e0 100644 --- a/src/charging-station/StationWorker.ts +++ b/src/charging-station/StationWorker.ts @@ -22,7 +22,7 @@ if (Utils.workerPoolInUse()) { * Listen messages send by the main thread */ function addMessageListener(): void { - parentPort.on('message', (message) => { + parentPort?.on('message', (message) => { if (message.id === WorkerEvents.START_WORKER_ELEMENT) { startChargingStation(message.workerData); } diff --git a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts index d74de14e..f230b3bc 100644 --- a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts @@ -190,7 +190,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer let clearedCP = false; for (const connector in this.chargingStation.connectors) { if (!Utils.isEmptyArray(this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles)) { - this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { + this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { let clearCurrentCP = false; if (chargingProfile.chargingProfileId === commandPayload.id) { clearCurrentCP = true; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 1a91cc8b..70742ea8 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,5 +1,5 @@ import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction'; -import { IncomingRequestCommand, Request, RequestCommand } from '../../types/ocpp/Requests'; +import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests'; import { BootNotificationResponse } from '../../types/ocpp/Responses'; import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; @@ -32,7 +32,7 @@ export default abstract class OCPPRequestService { // Request case MessageType.CALL_MESSAGE: // Build request - this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams] as Request; + this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams as Record]; messageToSend = JSON.stringify([messageType, messageId, commandName, commandParams]); break; // Response diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 26283cc9..aeb6828c 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -27,6 +27,6 @@ export const IncomingRequestCommand = { ...OCPP16IncomingRequestCommand }; -export type Request = [(payload: Record, requestPayload: Record) => void, (error: OCPPError) => void, Record]; +export type Request = [(payload: Record | string, requestPayload: Record) => void, (error: OCPPError) => void, Record]; export type IncomingRequest = [MessageType, string, IncomingRequestCommand, Record, Record]; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 1a2b714a..0926115c 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -9,7 +9,7 @@ import path from 'path'; export default class Configuration { private static configurationFilePath = path.join(path.resolve(__dirname, '../'), 'assets', 'config.json'); private static configurationFileWatcher: fs.FSWatcher; - private static configuration: ConfigurationData; + private static configuration: ConfigurationData | null = null; private static configurationChangeCallback: () => Promise; static setConfigurationChangeCallback(cb: () => Promise): void { @@ -143,7 +143,7 @@ export default class Configuration { } private static objectHasOwnProperty(object: any, property: string): boolean { - return Object.prototype.hasOwnProperty.call(object, property) as boolean; + return Object.prototype.hasOwnProperty.call(object, property); } private static isUndefined(obj: any): boolean { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index b975d0a4..6d37271f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -36,7 +36,7 @@ export default class Utils { } } - static convertToDate(value): Date { + static convertToDate(value: any): Date { // Check if (!value) { return value; @@ -48,7 +48,7 @@ export default class Utils { return value; } - static convertToInt(value): number { + static convertToInt(value: any): number { let changedValue = value; if (!value) { return 0; @@ -64,7 +64,7 @@ export default class Utils { return changedValue; } - static convertToFloat(value): number { + static convertToFloat(value: any): number { let changedValue = value; if (!value) { return 0; @@ -77,7 +77,7 @@ export default class Utils { return changedValue; } - static convertToBoolean(value): boolean { + static convertToBoolean(value: any): boolean { let result = false; // Check boolean if (value) { @@ -137,7 +137,7 @@ export default class Utils { return false; } - static isEmptyJSon(document): boolean { + static isEmptyJSon(document: any): boolean { // Empty? if (!document) { return true; @@ -150,15 +150,15 @@ export default class Utils { return Object.keys(document).length === 0; } - static isString(value): boolean { + static isString(value: any): boolean { return typeof value === 'string'; } - static isUndefined(value): boolean { + static isUndefined(value: any): boolean { return typeof value === 'undefined'; } - static isNullOrUndefined(value): boolean { + static isNullOrUndefined(value: any): boolean { // eslint-disable-next-line no-eq-null, eqeqeq if (value == null) { return true; @@ -166,7 +166,7 @@ export default class Utils { return false; } - static isEmptyArray(object): boolean { + static isEmptyArray(object: any): boolean { if (!object) { return true; } @@ -176,7 +176,7 @@ export default class Utils { return true; } - static isEmptyObject(obj): boolean { + static isEmptyObject(obj: any): boolean { return !Object.keys(obj).length; } diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 772bf1b4..71577816 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -5,7 +5,7 @@ export default abstract class WorkerAbstract { protected readonly workerScript: string; protected readonly workerStartDelay: number; public abstract size: number; - public abstract maxElementsPerWorker: number; + public abstract maxElementsPerWorker: number | null; /** * `WorkerAbstract` constructor. diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index a8f68978..9141c2f0 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -26,7 +26,7 @@ export default class WorkerDynamicPool extends WorkerAbstract { return this.pool.workers.length; } - get maxElementsPerWorker(): number { + get maxElementsPerWorker(): number | null { return null; } @@ -50,7 +50,7 @@ export default class WorkerDynamicPool extends WorkerAbstract { /** * - * @param elementData + * @param {T} elementData * @returns {Promise} * @public */ @@ -70,7 +70,7 @@ class DynamicPool extends DynamicThreadPool { public static getInstance(min: number, max: number, workerScript: string, opts?: PoolOptions): DynamicPool { if (!DynamicPool.instance) { - opts.exitHandler = opts.exitHandler ?? ((code) => { + opts.exitHandler = opts?.exitHandler ?? ((code) => { if (code !== 0) { console.error(`Worker stopped with exit code ${code}`); } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 2cda0ca2..f4307be6 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -8,7 +8,7 @@ import WorkerStaticPool from './WorkerStaticPool'; import { isMainThread } from 'worker_threads'; export default class WorkerFactory { - public static getWorkerImplementation(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): WorkerAbstract { + public static getWorkerImplementation(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): WorkerAbstract | null { if (!isMainThread) { throw new Error('Trying to get a worker implementation outside the main thread'); } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index dd12fdb5..21f9f482 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -27,7 +27,7 @@ export default class WorkerSet extends WorkerAbstract { /** * - * @param elementData + * @param {T} elementData * @returns {Promise} * @public */ diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 076b1ee0..7a304b70 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -25,7 +25,7 @@ export default class WorkerStaticPool extends WorkerAbstract { return this.pool.workers.length; } - get maxElementsPerWorker(): number { + get maxElementsPerWorker(): number | null { return null; } @@ -48,7 +48,7 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * - * @param elementData + * @param {T} elementData * @returns {Promise} * @public */ @@ -68,7 +68,7 @@ class StaticPool extends FixedThreadPool { public static getInstance(numberOfThreads: number, workerScript: string, opts?: PoolOptions): StaticPool { if (!StaticPool.instance) { - opts.exitHandler = opts.exitHandler ?? ((code) => { + opts.exitHandler = opts?.exitHandler ?? ((code) => { if (code !== 0) { console.error(`Worker stopped with exit code ${code}`); } diff --git a/tsconfig.json b/tsconfig.json index e217455b..1fd8e1cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,9 +5,9 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ "target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ "lib": [ - "es7" + "es2020" ], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ -- 2.34.1