My structure looks like this:
export interface AppConfig {
encryptionKey: string;
db: TypeOrmModuleOptions;
}
export interface BrandsConfig {
/**
* Brand name
*/
[key: string]: AppConfig;
}
export interface IConfig {
brands: BrandsConfig;
master: string;
}
export class Config implements IConfig {
public readonly brands: BrandsConfig;
public readonly master: string;
public constructor(init: IConfig) {
Object.assign(this, init);
}
}
The concept behind BrandsConfig is to be a collection of key/value pairs, where each key represents a brand name and the value is a setting specific to that brand. On the other hand, "master" is intended to designate one instance with a special status.
I am exploring a way to statically constrain the possible values of "master", ensuring that it aligns with the keys available in BrandsConfig. While I could perform this validation at runtime in the constructor, my aim is to shift such checks to the compilation phase for enhanced intellisense support. Is there a method to achieve this, potentially at the interface level as well as within the Config class?