Use generic for typing cloneObject helper.
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 22 Dec 2020 15:37:02 +0000 (16:37 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 22 Dec 2020 15:37:02 +0000 (16:37 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/utils/Utils.ts

index ada1c4b9e19c743c7fbcbbee7ca5925d5aaf1a88..ab3986bebf327fff26aa5d69d5e687d43b69b89c 100644 (file)
@@ -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<Connector>(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<Connector>(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<string|string[]>(this._stationInfo.supervisionURL ? this._stationInfo.supervisionURL : Configuration.getSupervisionURLs()) ;
     let indexUrl = 0;
     if (!Utils.isEmptyArray(supervisionUrls)) {
       if (Configuration.getDistributeStationsToTenantsEqually()) {
index cfa63cae2213bb7ea5649b304ca4db3fdcf8f134..83cb66ecfb2605c481695594a4cb89a99b8de9ea 100644 (file)
@@ -123,8 +123,8 @@ export default class Utils {
     return date.toLocaleString() + prefixString;
   }
 
-  static cloneObject(object) {
-    return JSON.parse(JSON.stringify(object));
+  static cloneObject<T>(object: T): T {
+    return JSON.parse(JSON.stringify(object)) as T;
   }
 
   static isIterable(obj): boolean {