CODEBASE: Update SaveData type to be compatible with TS 5.9 and upgrade TS (#2457)

This commit is contained in:
catloversg
2026-01-29 03:26:06 +07:00
committed by GitHub
parent afddd284fc
commit 8b07879ad9
9 changed files with 26 additions and 16 deletions
+12 -1
View File
@@ -1,4 +1,4 @@
import type { Unknownify } from "../types";
import type { SaveData, Unknownify } from "../types";
// This function is empty because Unknownify<T> is a typesafe assertion on any object with no runtime checks needed.
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -89,3 +89,14 @@ export function assertNumberArray(unknownData: unknown, assertFinite = false): a
}
}
}
export function assertSaveData(unknownData: unknown): asserts unknownData is SaveData {
if (typeof unknownData !== "string" && !(unknownData instanceof Uint8Array)) {
console.error(unknownData);
throw new Error(`Invalid save data. Its type is ${getFriendlyType(unknownData)}.`);
}
if (unknownData instanceof Uint8Array && !(unknownData.buffer instanceof ArrayBuffer)) {
console.error(unknownData);
throw new Error("Invalid save data. It's Uint8Array, but its buffer is not ArrayBuffer.");
}
}