Skip to content

Commit

Permalink
CODEBASE: Add comments to Generic_fromJSON (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg authored Nov 18, 2024
1 parent 93a9475 commit d824cd4
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 d824cd4

Please sign in to comment.