mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 04:47:03 +02:00
CODEBASE: Fix lint errors 3 (#1758)
This is a really big refactor because it actually *fixes* a lot of the lint errors instead of disabling them.
This commit is contained in:
+12
-1
@@ -1,3 +1,4 @@
|
||||
import { arrayAssert } from "../utils/helpers/typeAssertion";
|
||||
import type { IReviverValue } from "../utils/JSONReviver";
|
||||
// Versions of js builtin classes that can be converted to and from JSON for use in save files
|
||||
|
||||
@@ -6,6 +7,7 @@ export class JSONSet<T> extends Set<T> {
|
||||
return { ctor: "JSONSet", data: Array.from(this) };
|
||||
}
|
||||
static fromJSON(value: IReviverValue): JSONSet<any> {
|
||||
arrayAssert(value.data);
|
||||
return new JSONSet(value.data);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +18,15 @@ export class JSONMap<K, __V> extends Map<K, __V> {
|
||||
}
|
||||
|
||||
static fromJSON(value: IReviverValue): JSONMap<any, any> {
|
||||
return new JSONMap(value.data);
|
||||
arrayAssert(value.data);
|
||||
for (const item of value.data) {
|
||||
arrayAssert(item);
|
||||
if (item.length !== 2) {
|
||||
console.error("Invalid data passed to JSONMap.fromJSON(). Value:", value);
|
||||
throw new Error(`An item is not an array with exactly 2 items. Its length is ${item.length}.`);
|
||||
}
|
||||
}
|
||||
// We validated the data above, so it's safe to typecast here.
|
||||
return new JSONMap(value.data as [unknown, unknown][]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user