js2ts: util.ts 분리

This commit is contained in:
2021-08-21 20:45:10 +09:00
parent edbe8e3561
commit f23ebcdc2d
16 changed files with 56 additions and 86 deletions
+10
View File
@@ -0,0 +1,10 @@
import { Nullable } from "./Nullable";
type ErrType<T> = { new(msg?: string): T }
export function unwrap_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;
}