wip: 개체 작업 진행
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user