js2ts: util.ts 분리
This commit is contained in:
@@ -2,7 +2,7 @@ import $ from 'jquery';
|
||||
import 'bootstrap';
|
||||
import { DateTime } from 'luxon';
|
||||
import download from 'downloadjs';
|
||||
import { unwrap } from './util';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { isInteger } from 'lodash';
|
||||
import { combineArray, errUnknown, getNpcColor, isBrightColor, numberWithCommas } from './common_legacy';
|
||||
import { unwrap_any } from './util/unwrap_any';
|
||||
|
||||
@@ -4,7 +4,7 @@ import { range } from 'lodash';
|
||||
import { DateTime } from 'luxon';
|
||||
import { errUnknown, getNpcColor } from './common_legacy';
|
||||
import { InvalidResponse } from './defs';
|
||||
import { unwrap } from './util';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { convertFormData } from './util/convertFormData';
|
||||
import { unwrap_any } from "./util/unwrap_any";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { unwrap } from "./util";
|
||||
import { unwrap } from "./util/unwrap";
|
||||
|
||||
import jQuery from "jquery";
|
||||
import 'bootstrap';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from "axios";
|
||||
import { RuntimeError, unwrap } from "./util";
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { RuntimeError } from "./util/RuntimeError";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "../scss/inheritPoint.scss";
|
||||
|
||||
import { sum } from "lodash";
|
||||
import { unwrap } from "./util";
|
||||
import { unwrap } from "./util/unwrap";
|
||||
declare global {
|
||||
interface Window {
|
||||
formStart: ()=>void;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import $ from 'jquery';
|
||||
import { extend, isNumber } from 'lodash';
|
||||
import { convColorValue, convertDictById, convertSet } from './common_legacy';
|
||||
import { InvalidResponse } from './defs';
|
||||
import { unwrap } from './util';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { convertFormData } from './util/convertFormData';
|
||||
|
||||
declare const serverNick: string;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { convertFormData } from './util/convertFormData';
|
||||
import { InvalidResponse } from './defs';
|
||||
import { unwrap_any } from './util/unwrap_any';
|
||||
import { DataFormat, IdTextPair, OptionData } from 'select2';
|
||||
import { unwrap } from './util';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
|
||||
declare const isChiefTurn: boolean;
|
||||
declare global {
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
export class NotNullExpected extends TypeError {
|
||||
public name = 'NotNullExpected';
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export type Nullable<T> = T | null | undefined;
|
||||
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Nullable } from "./Nullable";
|
||||
import { NotNullExpected } from "./NotNullExpected";
|
||||
|
||||
export function unwrap<T>(result: Nullable<T>): T {
|
||||
if (result === null || result === undefined) {
|
||||
throw new NotNullExpected();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Nullable, NotNullExpected } from "../util";
|
||||
import { Nullable } from "./Nullable";
|
||||
import { NotNullExpected } from "./NotNullExpected";
|
||||
|
||||
|
||||
export function unwrap_any<T>(result: Nullable<unknown>): T {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
+1
-1
@@ -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
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user