From 29a04ab52dbd381ca34fa2e09235a13a5817d8ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 Mar 2026 16:28:26 +0100 Subject: [PATCH] refactor: type deprecated config key maps with `keyof` to eliminate 4 casts --- src/utils/Configuration.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 1b1adf92..fbe02787 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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 = {} for (const [deprecatedKey, newKey] of deprecatedLogKeyMap) { if (has(deprecatedKey, configData)) { - deprecatedLogConfiguration[newKey] = (configData as unknown as Record)[ - 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 = {} for (const [deprecatedKey, newKey] of deprecatedWorkerKeyMap) { if (has(deprecatedKey, configData)) { - deprecatedWorkerConfiguration[newKey] = (configData as unknown as Record)[ - deprecatedKey - ] + deprecatedWorkerConfiguration[newKey] = configData?.[deprecatedKey] } } if (has('elementStartDelay', configData?.worker)) { - deprecatedWorkerConfiguration.elementAddDelay = ( - configData?.worker as unknown as Record - ).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).workerPoolStrategy const workerConfiguration: WorkerConfiguration = { ...defaultWorkerConfiguration, ...(deprecatedWorkerConfiguration as Partial), -- 2.53.0