mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-14 03:20:07 +02:00
DARKNET: Darkweb Expansion Project & Bitnode (#2139)
This is BN15. It is a really big change; see the PR for all the details.
This commit is contained in:
committed by
GitHub
parent
a674633f6c
commit
6073964768
@@ -100,3 +100,23 @@ export function assertSaveData(unknownData: unknown): asserts unknownData is Sav
|
||||
throw new Error("Invalid save data. It's Uint8Array, but its buffer is not ArrayBuffer.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function only narrows down the type to "number" at compile time, but it guarantees the value is a finite number
|
||||
* at runtime.
|
||||
*/
|
||||
export function assertFiniteNumber(v: unknown): asserts v is number {
|
||||
if (!Number.isFinite(v)) {
|
||||
console.error("The value is not a finite number. Value:", v);
|
||||
const type = getFriendlyType(v);
|
||||
throw new TypeAssertionError(`The value is not a finite number. Its type is ${type}.`, type);
|
||||
}
|
||||
}
|
||||
|
||||
export function assertNonNullish<T>(v: unknown): asserts v is NonNullable<T> {
|
||||
if (v === null || v === undefined) {
|
||||
console.error("The value is nullish. Value:", v);
|
||||
const type = getFriendlyType(v);
|
||||
throw new TypeAssertionError(`The value is nullish. Its type is ${type}.`, type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user