From e56aa9a485910df535a991f0d6452ec2931d209e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 22 Dec 2020 16:37:02 +0100 Subject: [PATCH] Use generic for typing cloneObject helper. 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 | 6 +++--- src/utils/Utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index ada1c4b9..ab3986be 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -136,14 +136,14 @@ export default class ChargingStation { let lastConnector = '0'; for (lastConnector in this._stationInfo.Connectors) { if (Utils.convertToInt(lastConnector) === 0 && this._getUseConnectorId0() && this._stationInfo.Connectors[lastConnector]) { - this._connectors[lastConnector] = Utils.cloneObject(this._stationInfo.Connectors[lastConnector]) as Connector; + this._connectors[lastConnector] = Utils.cloneObject(this._stationInfo.Connectors[lastConnector]); } } // Generate all connectors if ((this._stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0) { for (let index = 1; index <= maxConnectors; index++) { const randConnectorID = this._stationInfo.randomConnectors ? Utils.getRandomInt(Utils.convertToInt(lastConnector), 1) : index; - this._connectors[index] = Utils.cloneObject(this._stationInfo.Connectors[randConnectorID]) as Connector; + this._connectors[index] = Utils.cloneObject(this._stationInfo.Connectors[randConnectorID]) ; } } } @@ -339,7 +339,7 @@ export default class ChargingStation { } _getSupervisionURL(): string { - const supervisionUrls = Utils.cloneObject(this._stationInfo.supervisionURL ? this._stationInfo.supervisionURL : Configuration.getSupervisionURLs()) as string | string[]; + const supervisionUrls = Utils.cloneObject(this._stationInfo.supervisionURL ? this._stationInfo.supervisionURL : Configuration.getSupervisionURLs()) ; let indexUrl = 0; if (!Utils.isEmptyArray(supervisionUrls)) { if (Configuration.getDistributeStationsToTenantsEqually()) { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index cfa63cae..83cb66ec 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -123,8 +123,8 @@ export default class Utils { return date.toLocaleString() + prefixString; } - static cloneObject(object) { - return JSON.parse(JSON.stringify(object)); + static cloneObject(object: T): T { + return JSON.parse(JSON.stringify(object)) as T; } static isIterable(obj): boolean { -- 2.34.1