X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=8d51349a2357fbb9ea0b450dd3367f00f8c7406e;hb=a37fc6dc8267e22b2b2d35773525980b81f014e8;hp=eba8ca447082243a9c343e0ee50ed09d9274f0a0;hpb=58ddf341890de6554fc6c5325f82a33f3e4b3632;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index eba8ca44..8d51349a 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -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 = (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 => { @@ -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)'; };