fix: fix ATG configuration save at template reload
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 3ef99c5f2fdcab960c8e8234371eba0830d59c51..c2c9d0ad22ac7152a5dd2565d166f278b5cd7ef3 100644 (file)
@@ -21,7 +21,7 @@ export const validateUUID = (uuid: string): boolean => {
 };
 
 export const sleep = async (milliSeconds: number): Promise<NodeJS.Timeout> => {
-  return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds));
+  return new Promise<NodeJS.Timeout>((resolve) => setTimeout(resolve as () => void, milliSeconds));
 };
 
 export const formatDurationMilliSeconds = (duration: number): string => {
@@ -59,7 +59,7 @@ export const convertToDate = (
     return value;
   }
   if (isString(value) || typeof value === 'number') {
-    return new Date(value);
+    return new Date(value!);
   }
   return null;
 };
@@ -79,6 +79,7 @@ export const convertToInt = (value: unknown): number => {
     changedValue = parseInt(value as string);
   }
   if (isNaN(changedValue)) {
+    // eslint-disable-next-line @typescript-eslint/no-base-to-string
     throw new Error(`Cannot convert to integer: ${value.toString()}`);
   }
   return changedValue;
@@ -93,6 +94,7 @@ export const convertToFloat = (value: unknown): number => {
     changedValue = parseFloat(value as string);
   }
   if (isNaN(changedValue)) {
+    // eslint-disable-next-line @typescript-eslint/no-base-to-string
     throw new Error(`Cannot convert to float: ${value.toString()}`);
   }
   return changedValue;
@@ -196,7 +198,7 @@ export const isCFEnvironment = (): boolean => {
 };
 
 export const isIterable = <T>(obj: T): boolean => {
-  return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
+  return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator as keyof T] === 'function' : false;
 };
 
 const isString = (value: unknown): boolean => {
@@ -297,7 +299,7 @@ export const JSONStringifyWithMapSupport = (
 ): string => {
   return JSON.stringify(
     obj,
-    (key, value: Record<string, unknown>) => {
+    (_, value: Record<string, unknown>) => {
       if (value instanceof Map) {
         return {
           dataType: 'Map',
@@ -330,8 +332,12 @@ export const getWebSocketCloseEventStatusString = (code: number): string => {
       return '(For applications)';
     }
   }
-  if (!isUndefined(WebSocketCloseEventStatusString[code])) {
-    return WebSocketCloseEventStatusString[code] as string;
+  if (
+    !isUndefined(
+      WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString],
+    )
+  ) {
+    return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString];
   }
   return '(Unknown)';
 };