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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -102,6 +102,7 @@ export function Generic_fromJSON<T extends Record<string, any>>(
for (const key of keys as string[]) { for (const key of keys as string[]) {
const val = data[key]; const val = data[key];
if (val !== undefined) { 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. // @ts-expect-error -- TypeScript won't allow this action: Type 'T' is generic and can only be indexed for reading.
obj[key] = val; obj[key] = val;
} }
@ -109,6 +110,9 @@ export function Generic_fromJSON<T extends Record<string, any>>(
return obj; return obj;
} }
// No keys provided: load every key in data // 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; return obj;
} }