mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 07:33:48 +01:00
CODEBASE: Add comments to Generic_fromJSON (#1776)
This commit is contained in:
parent
93a9475b8d
commit
d824cd4fa6
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user