From 97608fbd74bbcefe7733ab1a9f9612ae0811c438 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 4 Jan 2024 16:23:09 +0100 Subject: [PATCH] refactor: cleanup a few unneeded type casting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 12 ++++++------ src/charging-station/ocpp/OCPPServiceUtils.ts | 2 +- src/charging-station/ui-server/UIWebSocketServer.ts | 2 +- src/utils/ErrorUtils.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 8029178b..a6721c53 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -263,7 +263,7 @@ export class ChargingStation extends EventEmitter { public getNumberOfPhases (stationInfo?: ChargingStationInfo): number { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo! + const localStationInfo = stationInfo ?? this.stationInfo! switch (this.getCurrentOutType(stationInfo)) { case CurrentType.AC: return localStationInfo.numberOfPhases ?? 3 @@ -1092,14 +1092,14 @@ export class ChargingStation extends EventEmitter { private getStationInfoFromTemplate (): ChargingStationInfo { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const stationTemplate: ChargingStationTemplate = this.getTemplateFromFile()! + const stationTemplate = this.getTemplateFromFile()! checkTemplate(stationTemplate, this.logPrefix(), this.templateFile) const warnTemplateKeysDeprecationOnce = once(warnTemplateKeysDeprecation, this) warnTemplateKeysDeprecationOnce(stationTemplate, this.logPrefix(), this.templateFile) if (stationTemplate.Connectors != null) { checkConnectorsConfiguration(stationTemplate, this.logPrefix(), this.templateFile) } - const stationInfo: ChargingStationInfo = stationTemplateToStationInfo(stationTemplate) + const stationInfo = stationTemplateToStationInfo(stationTemplate) stationInfo.hashId = getHashId(this.index, stationTemplate) stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate) stationInfo.ocppVersion = stationTemplate.ocppVersion ?? OCPPVersion.VERSION_16 @@ -1164,8 +1164,8 @@ export class ChargingStation extends EventEmitter { private getStationInfo (): ChargingStationInfo { const defaultStationInfo = Constants.DEFAULT_STATION_INFO - const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate() - const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile( + const stationInfoFromTemplate = this.getStationInfoFromTemplate() + const stationInfoFromFile = this.getStationInfoFromFile( stationInfoFromTemplate.stationInfoPersistentConfiguration ) // Priority: @@ -2229,7 +2229,7 @@ export class ChargingStation extends EventEmitter { } private startWebSocketPing (): void { - const webSocketPingInterval: number = + const webSocketPingInterval = getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) != null ? convertToInt( getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 51a9948e..e73caca4 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1115,7 +1115,7 @@ const getSampledValueTemplate = ( ) return } - const sampledValueTemplates: SampledValueTemplate[] = + const sampledValueTemplates = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion chargingStation.getConnectorStatus(connectorId)!.MeterValues for ( diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 6d6dc6df..c135cb13 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -53,7 +53,7 @@ export class UIWebSocketServer extends AbstractUIServer { ws.close(WebSocketCloseEventStatusCode.CLOSE_INVALID_PAYLOAD) return } - const [requestId] = request as ProtocolRequest + const [requestId] = request this.responseHandlers.set(requestId, ws) this.uiServices .get(version) diff --git a/src/utils/ErrorUtils.ts b/src/utils/ErrorUtils.ts index 41a61acc..bd4fcf37 100644 --- a/src/utils/ErrorUtils.ts +++ b/src/utils/ErrorUtils.ts @@ -17,7 +17,7 @@ import type { const defaultErrorParams = { throwError: true, consoleOut: false -} +} satisfies HandleErrorParams export const handleUncaughtException = (): void => { process.on('uncaughtException', (error: Error) => { -- 2.34.1