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
+10 -2
View File
@@ -23,10 +23,18 @@ export const debugType = (v: unknown): string => {
return `Is of type '${typeof v}', value: ${userFriendlyString(v)}`;
};
export function assertString(ctx: NetscriptContext, argName: string, v: unknown): asserts v is string {
/**
* This function should be used to assert strings provided by the player. It uses a specialized utility function that
* provides a stack trace pointing to the player's invalid caller.
*/
export function assertStringWithNSContext(ctx: NetscriptContext, argName: string, v: unknown): asserts v is string {
if (typeof v !== "string") throw errorMessage(ctx, `${argName} expected to be a string. ${debugType(v)}`, "TYPE");
}
export function assertFunction(ctx: NetscriptContext, argName: string, v: unknown): asserts v is () => void {
export function assertFunctionWithNSContext(
ctx: NetscriptContext,
argName: string,
v: unknown,
): asserts v is () => void {
if (typeof v !== "function") throw errorMessage(ctx, `${argName} expected to be a function ${debugType(v)}`, "TYPE");
}