Problem
In validateConfigTypes(), the pattern (validated as Record<string, unknown>)[field] is repeated 5 times (lines 67, 77, 89, 101) as a workaround for TypeScript not allowing delete on Partial<T> fields cleanly. This undermines the type safety that the function is supposed to enforce.
Proposed Solution
Introduce a typed helper function to encapsulate the unsafe cast:
function deleteField(obj: Partial<LeonidasConfig>, field: keyof LeonidasConfig): void {
delete (obj as Record<string, unknown>)[field];
}
function setField<K extends keyof LeonidasConfig>(
obj: Partial<LeonidasConfig>,
field: K,
value: LeonidasConfig[K],
): void {
(obj as Record<string, unknown>)[field] = value;
}
This confines the unsafe cast to a single location, making the rest of the validation code type-safe and easier to read.
Affected Files
src/config.ts (only file affected)
Risk
Very Low — internal type handling improvement, no behavior change.
Notes
- Independent of other refactoring tasks
- Phase 4 of the refactoring plan
Problem
In
validateConfigTypes(), the pattern(validated as Record<string, unknown>)[field]is repeated 5 times (lines 67, 77, 89, 101) as a workaround for TypeScript not allowingdeleteonPartial<T>fields cleanly. This undermines the type safety that the function is supposed to enforce.Proposed Solution
Introduce a typed helper function to encapsulate the unsafe cast:
This confines the unsafe cast to a single location, making the rest of the validation code type-safe and easier to read.
Affected Files
src/config.ts(only file affected)Risk
Very Low — internal type handling improvement, no behavior change.
Notes