Files
core/hwe/ts/util.ts
T
Hide_D bc218b73e1 js2ts: chiefCenter
- common: unwrap_any
- jQuery export 수정
- axios로 변경
- moment -> luxon
2021-08-16 01:06:17 +09:00

35 lines
912 B
TypeScript

type ErrType<T> = { new(msg?: string): T }
export 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;
}