From: Jérôme Benoit Date: Mon, 17 Jul 2023 10:15:37 +0000 (+0200) Subject: refactor: improve configuration section typing X-Git-Tag: v1.2.18~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e7c0fce05d773fcc1dd2fb285f824808a5dee243;p=e-mobility-charging-stations-simulator.git refactor: improve configuration section typing Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 66abd3e1..54f6b745 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -22,6 +22,12 @@ import { } from '../types'; import { WorkerConstants, WorkerProcessType } from '../worker'; +type ConfigurationSectionType = + | LogConfiguration + | StorageConfiguration + | WorkerConfiguration + | UIServerConfiguration; + export class Configuration { private static configurationFile = join( dirname(fileURLToPath(import.meta.url)), @@ -33,7 +39,7 @@ export class Configuration { private static configurationData: ConfigurationData | null = null; private static configurationSectionCache = new Map< ConfigurationSection, - LogConfiguration | StorageConfiguration | WorkerConfiguration | UIServerConfiguration + ConfigurationSectionType >([ [ConfigurationSection.log, Configuration.buildLogSection()], [ConfigurationSection.performanceStorage, Configuration.buildPerformanceStorageSection()], @@ -51,7 +57,9 @@ export class Configuration { Configuration.configurationChangeCallback = cb; } - public static getConfigurationSection(sectionName: ConfigurationSection): T { + public static getConfigurationSection( + sectionName: ConfigurationSection, + ): T { if (!Configuration.configurationSectionCache.has(sectionName)) { switch (sectionName) { case ConfigurationSection.log: