File size: 1,361 Bytes
31dd200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /**
* Type-safe configuration helpers
*
* Provides utilities for safely accessing and modifying configuration objects
* with dynamic keys while maintaining TypeScript type safety.
*/
/**
* Type-safe helper to access config properties dynamically
* Provides better type safety than direct casting to Record
*/
export function setConfigValue<T extends SettingsConfigType>(
config: T,
key: string,
value: unknown
): void {
if (key in config) {
(config as Record<string, unknown>)[key] = value;
}
}
/**
* Type-safe helper to get config values dynamically
*/
export function getConfigValue<T extends SettingsConfigType>(
config: T,
key: string
): string | number | boolean | undefined {
const value = (config as Record<string, unknown>)[key];
return value as string | number | boolean | undefined;
}
/**
* Convert a SettingsConfigType to a ParameterRecord for specific keys
* Useful for parameter synchronization operations
*/
export function configToParameterRecord<T extends SettingsConfigType>(
config: T,
keys: string[]
): Record<string, string | number | boolean> {
const record: Record<string, string | number | boolean> = {};
for (const key of keys) {
const value = getConfigValue(config, key);
if (value !== undefined) {
record[key] = value;
}
}
return record;
}
|