유산 보기 페이지

This commit is contained in:
2021-08-11 02:32:41 +09:00
parent e5b5c5e1cf
commit ea58e1e5c5
5 changed files with 83 additions and 22 deletions
+35
View File
@@ -0,0 +1,35 @@
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;
}