CODEBASE: Merge TypeAssertion files (#1922)

This commit is contained in:
catloversg
2025-01-25 02:06:39 +07:00
committed by GitHub
parent f0a0d3095e
commit 9bf408221c
19 changed files with 125 additions and 111 deletions
+4 -4
View File
@@ -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}.`);