CODEBASE: Add comments to Generic_fromJSON (#1776)

This commit is contained in:
catloversg
2024-11-19 06:36:23 +07:00
committed by GitHub
parent 93a9475b8d
commit d824cd4fa6

View File

@@ -102,6 +102,7 @@ export function Generic_fromJSON<T extends Record<string, any>>(
for (const key of keys as string[]) {
const val = data[key];
if (val !== undefined) {
// This is an unsafe assignment. We may load data with wrong types at runtime.
// @ts-expect-error -- TypeScript won't allow this action: Type 'T' is generic and can only be indexed for reading.
obj[key] = val;
}
@@ -109,6 +110,9 @@ export function Generic_fromJSON<T extends Record<string, any>>(
return obj;
}
// No keys provided: load every key in data
for (const [key, val] of Object.entries(data) as [keyof T, T[keyof T]][]) obj[key] = val;
for (const [key, val] of Object.entries(data) as [keyof T, T[keyof T]][]) {
// This is an unsafe assignment. We may load data with wrong types at runtime.
obj[key] = val;
}
return obj;
}