mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-24 00:16:34 +02:00
CODEBASE: Merge TypeAssertion files (#1922)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { arrayAssert } from "../utils/helpers/typeAssertion";
|
||||
import { assertArray } from "../utils/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
|
||||
|
||||
@@ -7,7 +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);
|
||||
assertArray(value.data);
|
||||
return new JSONSet(value.data);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ export class JSONMap<K, __V> extends Map<K, __V> {
|
||||
}
|
||||
|
||||
static fromJSON(value: IReviverValue): JSONMap<any, any> {
|
||||
arrayAssert(value.data);
|
||||
assertArray(value.data);
|
||||
for (const item of value.data) {
|
||||
arrayAssert(item);
|
||||
assertArray(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}.`);
|
||||
|
||||
Reference in New Issue
Block a user