fix: tidy up deleteundefinedprops and validate against arrays

This commit is contained in:
zkldi
2022-05-06 03:42:41 +01:00
parent 0adc39b5cb
commit ba50d17846
+8 -4
View File
@@ -109,13 +109,17 @@ export function StripUrl(url: string, userInput: string | null) {
// runtime validation.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function DeleteUndefinedProps(record: any) {
if (typeof record !== "object" || record === null) {
if (typeof record !== "object" || record === null || Array.isArray(record)) {
throw new Error(`Non-object passed to DeleteUndefinedProps.`);
}
for (const key in record) {
if (record[key] === undefined) {
delete record[key];
// asserted above
const rec = record as Record<string, unknown>;
for (const key of Object.keys(rec)) {
if (rec[key] === undefined) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete rec[key];
}
}
}