refactor: use strict typing

This commit is contained in:
Carlos Valente
2025-03-21 19:44:16 +01:00
committed by arc-alex
parent 14a7c04d3b
commit d48b2ae506
39 changed files with 339 additions and 246 deletions
-28
View File
@@ -1,5 +1,4 @@
import { unlink } from 'fs';
import { deepmerge } from 'ontime-utils';
/**
* @description Ensures variable is string, it skips object types
@@ -35,33 +34,6 @@ export const isEmptyObject = (obj: object) => {
throw new Error('Variable is not an object');
};
/**
* @description Merges two objects, suppressing undefined keys
* @param {object} a - any object
* @param {object} b - a potential partial object of same time as a
*/
export function mergeObject<T extends object>(a: T, b: Partial<T>): T {
const merged = { ...a };
for (const key in b) {
const aValue = a[key];
const bValue = b[key];
// ignore keys that do not exist in original object
if (!Object.hasOwn(merged, key)) {
continue;
}
if (typeof bValue === 'object' && bValue !== null && typeof aValue === 'object' && aValue !== null) {
// @ts-expect-error -- not sure how to type this
merged[key] = deepmerge(aValue, bValue);
} else if (bValue !== undefined) {
merged[key] = bValue;
}
}
return merged;
}
/**
* @description Removes undefined
* @param {object} obj