refactor: improve configuration section typing
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 10:15:37 +0000 (12:15 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 10:15:37 +0000 (12:15 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Configuration.ts

index 66abd3e101dc6e427cac6c5c35babe61d9fdd02e..54f6b745610d6874d94d1cba52cdb5e59325b366 100644 (file)
@@ -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<T>(sectionName: ConfigurationSection): T {
+  public static getConfigurationSection<T extends ConfigurationSectionType>(
+    sectionName: ConfigurationSection,
+  ): T {
     if (!Configuration.configurationSectionCache.has(sectionName)) {
       switch (sectionName) {
         case ConfigurationSection.log: