fix: fix 'Cannot read properties of undefined' with revervation enabled
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index 0fae41f7ddd259b209d7d1a8132e3a00a8f9dbb7..383db84780f53aa22bb415ba7b3603e6b32bea2f 100644 (file)
@@ -623,7 +623,7 @@ const warnDeprecatedTemplateKey = (
   templateFile: string,
   logMsgToAppend = '',
 ): void => {
-  if (!isUndefined(template[key])) {
+  if (!isUndefined(template[key as keyof ChargingStationTemplate])) {
     const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
       isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
     }`;
@@ -637,11 +637,12 @@ const convertDeprecatedTemplateKey = (
   deprecatedKey: string,
   key?: string,
 ): void => {
-  if (!isUndefined(template[deprecatedKey])) {
+  if (!isUndefined(template[deprecatedKey as keyof ChargingStationTemplate])) {
     if (!isUndefined(key)) {
-      template[key!] = template[deprecatedKey] as unknown;
+      (template as unknown as Record<string, unknown>)[key!] =
+        template[deprecatedKey as keyof ChargingStationTemplate];
     }
-    delete template[deprecatedKey];
+    delete template[deprecatedKey as keyof ChargingStationTemplate];
   }
 };