Refactor: Improve env var resolution in settings

Refactors the `resolveEnvVarsInObject` function in settings to
explicitly handle primitive types (null, undefined, boolean, number)
at the beginning of the function. This clarifies the logic for
subsequent string, array, and object processing.
This commit is contained in:
jerop
2025-06-06 15:32:39 +00:00
committed by Jerop Kipruto
parent 4e9d365407
commit 8c28250bb3
2 changed files with 62 additions and 1 deletions

View File

@@ -110,6 +110,15 @@ function resolveEnvVarsInString(value: string): string {
}
function resolveEnvVarsInObject<T>(obj: T): T {
if (
obj === null ||
obj === undefined ||
typeof obj === 'boolean' ||
typeof obj === 'number'
) {
return obj;
}
if (typeof obj === 'string') {
return resolveEnvVarsInString(obj) as unknown as T;
}
@@ -118,7 +127,7 @@ function resolveEnvVarsInObject<T>(obj: T): T {
return obj.map((item) => resolveEnvVarsInObject(item)) as unknown as T;
}
if (obj && typeof obj === 'object') {
if (typeof obj === 'object') {
const newObj = { ...obj } as T;
for (const key in newObj) {
if (Object.prototype.hasOwnProperty.call(newObj, key)) {