Skip to content

Commit

Permalink
CODEBASE: Add comments to Generic_fromJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg committed Nov 15, 2024
1 parent 75cf9c8 commit 94ceac5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/JSONReviver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ 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;
}
}
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;
}

0 comments on commit 94ceac5

Please sign in to comment.