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
+1 -1
View File
@@ -7,7 +7,7 @@ import { DATE_TIME_FORMAT, getDateTimeNow } from "../hwe/ts/util/getDateTimeNow"
import { sha512 } from "js-sha512";
import { convertFormData } from "../hwe/ts/util/convertFormData";
import { InvalidResponse } from "../hwe/ts/defs";
import { unwrap } from "./util";
import { unwrap } from "../hwe/ts/util/unwrap";
type ResultUserInfo = {
result: true,
-35
View File
@@ -1,35 +0,0 @@
type ErrType<T> = { new(msg?: string): T }
type Nullable<T> = T | null | undefined
export class RuntimeError extends Error {
public name = 'RuntimeError';
constructor(public message: string = '') {
super(message);
}
toString(): string {
if (this.message) {
return this.name + ': ' + this.message;
}
else {
return this.name;
}
}
}
export class NotNullExpected extends RuntimeError {
public name = 'NotNullExpected';
}
export function unwrap<T>(result: Nullable<T>): T {
if (result === null || result === undefined) {
throw new NotNullExpected();
}
return result;
}
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;
}