]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor: type deprecated config key maps with `keyof` to eliminate 4 casts
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Mar 2026 15:28:26 +0000 (16:28 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Mar 2026 15:28:26 +0000 (16:28 +0100)
src/utils/Configuration.ts

index 1b1adf92c1cd84e9ca2f64bb6e458e5c9a066442..fbe027873766905e5c4581f7f8494c702b624937 100644 (file)
@@ -205,7 +205,7 @@ export class Configuration {
 
   private static buildLogSection (): LogConfiguration {
     const configData = Configuration.getConfigurationData()
-    const deprecatedLogKeyMap: [string, string][] = [
+    const deprecatedLogKeyMap: [keyof ConfigurationData, keyof LogConfiguration][] = [
       ['logEnabled', 'enabled'],
       ['logFile', 'file'],
       ['logErrorFile', 'errorFile'],
@@ -220,9 +220,7 @@ export class Configuration {
     const deprecatedLogConfiguration: Record<string, unknown> = {}
     for (const [deprecatedKey, newKey] of deprecatedLogKeyMap) {
       if (has(deprecatedKey, configData)) {
-        deprecatedLogConfiguration[newKey] = (configData as unknown as Record<string, unknown>)[
-          deprecatedKey
-        ]
+        deprecatedLogConfiguration[newKey] = configData?.[deprecatedKey]
       }
     }
     const logConfiguration: LogConfiguration = {
@@ -291,7 +289,7 @@ export class Configuration {
 
   private static buildWorkerSection (): WorkerConfiguration {
     const configData = Configuration.getConfigurationData()
-    const deprecatedWorkerKeyMap: [string, string][] = [
+    const deprecatedWorkerKeyMap: [keyof ConfigurationData, keyof WorkerConfiguration][] = [
       ['workerProcess', 'processType'],
       ['workerStartDelay', 'startDelay'],
       ['chargingStationsPerWorker', 'elementsPerWorker'],
@@ -302,18 +300,17 @@ export class Configuration {
     const deprecatedWorkerConfiguration: Record<string, unknown> = {}
     for (const [deprecatedKey, newKey] of deprecatedWorkerKeyMap) {
       if (has(deprecatedKey, configData)) {
-        deprecatedWorkerConfiguration[newKey] = (configData as unknown as Record<string, unknown>)[
-          deprecatedKey
-        ]
+        deprecatedWorkerConfiguration[newKey] = configData?.[deprecatedKey]
       }
     }
     if (has('elementStartDelay', configData?.worker)) {
-      deprecatedWorkerConfiguration.elementAddDelay = (
-        configData?.worker as unknown as Record<string, unknown>
-      ).elementStartDelay
+      // eslint-disable-next-line @typescript-eslint/no-deprecated -- intentional deprecated key migration
+      deprecatedWorkerConfiguration.elementAddDelay = configData?.worker?.elementStartDelay
+    }
+    if (configData != null) {
+      // eslint-disable-next-line @typescript-eslint/no-deprecated -- intentional deprecated key removal
+      delete configData.workerPoolStrategy
     }
-    has('workerPoolStrategy', configData) &&
-      delete (configData as unknown as Record<string, unknown>).workerPoolStrategy
     const workerConfiguration: WorkerConfiguration = {
       ...defaultWorkerConfiguration,
       ...(deprecatedWorkerConfiguration as Partial<WorkerConfiguration>),