wip: 개체 작업 진행

This commit is contained in:
2024-03-06 16:33:23 +00:00
parent be6e765d76
commit 21da4d14e6
9 changed files with 394 additions and 23 deletions
+1
View File
@@ -2,6 +2,7 @@ export * from "./bsonify.js"
export * from "./jsonify.js"
export * from "./error.js"
export * from "./unwrap.js"
export * from "./must.js"
export * from "./types.js"
export * from "./web.js"
+25
View File
@@ -0,0 +1,25 @@
import type { Nullable } from './types.js';
import { NotNullExpected } from "./error.js";
export function must<T>(result: Nullable<T>): T {
if (result === null || result === undefined) {
throw new NotNullExpected();
}
return result;
}
export function must_any<T>(result: Nullable<unknown>): T {
if (result === null || result === undefined) {
throw new NotNullExpected();
}
return result as T;
}
type ErrType<T> = { new(msg?: string): T }
export function must_err<T, ErrT extends Error>(result: Nullable<T>, errType: ErrType<ErrT>, errMsg?: string): T {
if (result === null || result === undefined) {
throw new errType(errMsg);
}
return result;
}