fix typeof

This commit is contained in:
Simon Larsen 2022-07-29 20:15:18 +01:00
parent 1804f5a0bf
commit c36754b662
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
12 changed files with 30 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import BadDataException from '../Exception/BadDataException';
import Port from '../Port';
import Typeof from '../Typeof';
export default class Hostname {
private _route: string = '';
@ -32,9 +33,9 @@ export default class Hostname {
if (port instanceof Port) {
this.port = port;
} else if (typeof port === Typeof.String) {
this.port = new Port(port);
} else if (typeof port === 'number') {
this.port = new Port(port);
this.port = new Port(port as string);
} else if (typeof port === Typeof.Number) {
this.port = new Port(port as number);
}
}

View File

@ -1,4 +1,5 @@
import PositiveNumber from '../PositiveNumber';
import Typeof from '../Typeof';
export default class StatusCode {
private _statusCode: PositiveNumber = new PositiveNumber(200);
@ -26,7 +27,7 @@ export default class StatusCode {
public static isValidStausCode(statusCode: number | string): boolean {
try {
if (typeof statusCode === Typeof.String) {
statusCode = parseInt(statusCode);
statusCode = parseInt(statusCode as string);
}
if (statusCode >= 100 && statusCode <= 599) {

View File

@ -4,6 +4,7 @@ import Hostname from './Hostname';
import DatabaseProperty from '../Database/DatabaseProperty';
import { FindOperator } from 'typeorm';
import Dictionary from '../Dictionary';
import Typeof from '../Typeof';
export default class URL extends DatabaseProperty {
private _route: Route = new Route();
@ -129,8 +130,10 @@ export default class URL extends DatabaseProperty {
public addRoute(route: Route | string): URL {
if (typeof route === Typeof.String) {
this.route.addRoute(new Route(route));
} else {
this.route.addRoute(new Route(route.toString()));
}
if(route instanceof Route){
this.route.addRoute(route);
}

View File

@ -1,4 +1,5 @@
import Email from './Email';
import Typeof from './Typeof';
export default class EmailWithName {
private _email: Email = new Email('noreply@oneuptime.com');
@ -7,7 +8,7 @@ export default class EmailWithName {
}
public set email(v: Email | string) {
if (typeof v === Typeof.String) {
this._email = new Email(v);
this._email = new Email(v.toString());
}
if (v instanceof Email) {

View File

@ -1,8 +1,9 @@
import Email from './Email';
import { JSONObject } from './JSON';
import Name from './Name';
import ObjectID from './ObjectID';
export default interface JSONWebTokenData {
export default interface JSONWebTokenData extends JSONObject {
userId: ObjectID;
email: Email;
name: Name;

View File

@ -1,5 +1,6 @@
import BadDataException from './Exception/BadDataException';
import PositiveNumber from './PositiveNumber';
import Typeof from './Typeof';
export default class Port {
private _port: PositiveNumber = new PositiveNumber(0);
@ -13,7 +14,7 @@ export default class Port {
public constructor(port: number | string) {
if (typeof port === Typeof.String) {
try {
port = Number.parseInt(port, 10);
port = Number.parseInt(port.toString(), 10);
} catch (error) {
throw new BadDataException(`Invalid port: ${port}`);
}

View File

@ -1,4 +1,5 @@
import BadDataException from './Exception/BadDataException';
import Typeof from './Typeof';
export default class PositiveNumber {
private _positiveNumber: number = 0;
@ -11,7 +12,7 @@ export default class PositiveNumber {
public constructor(positiveNumber: number | string) {
if (typeof positiveNumber === Typeof.String) {
positiveNumber = Number.parseInt(positiveNumber, 10);
positiveNumber = Number.parseInt(positiveNumber.toString(), 10);
if (isNaN(positiveNumber)) {
throw new BadDataException(`Invalid number: ${positiveNumber}`);
}
@ -21,7 +22,7 @@ export default class PositiveNumber {
throw new BadDataException('positiveNumber cannot be less than 0');
}
this.positiveNumber = positiveNumber;
this.positiveNumber = positiveNumber as number;
}
public toString(): string {

View File

@ -45,6 +45,7 @@ import DatabaseCommonInteractionProps from 'Common/Types/Database/DatabaseCommon
import QueryHelper from '../Types/Database/QueryHelper';
import { getUniqueColumnsBy } from 'Common/Types/Database/UniqueColumnBy';
import Search from 'Common/Types/Database/Search';
import Typeof from 'Common/Types/Typeof';
enum DatabaseRequestType {
Create = 'create',

View File

@ -15,9 +15,9 @@ class JSONWebToken {
): string {
let jsonObj: JSONObject;
if (typeof data === Typeof.String) {
if (typeof data === "string") {
jsonObj = {
data,
data: data.toString(),
};
} else if (!(data instanceof User)) {
jsonObj = {

View File

@ -26,7 +26,6 @@ import PermissionUtil from '../../Utils/Permission';
import { ColumnAccessControl } from 'Common/Types/Database/AccessControl/AccessControl';
import { getColumnAccessControlForAllColumns } from 'Common/Types/Database/AccessControl/ColumnAccessControl';
import Query from '../../Utils/ModelAPI/Query';
import { instanceOf } from 'prop-types';
import Search from 'Common/Types/Database/Search';
import Typeof from 'Common/Types/Typeof';
@ -234,7 +233,7 @@ const ModelTable: Function = <TBaseModel extends BaseModel>(
useEffect(() => {
fetchItems();
}, [currentPageNumber, sortBy, sortOrder, itemsOnPage]);
}, [currentPageNumber, sortBy, sortOrder, itemsOnPage, query]);
useEffect(() => {
@ -400,6 +399,8 @@ const ModelTable: Function = <TBaseModel extends BaseModel>(
query[key as keyof TBaseModel] = !!filterData[key];
}
}
setQuery(query);
}}
onSortChanged={(sortBy: string, sortOrder: SortOrder) => {
setSortBy(sortBy);

View File

@ -1,12 +1,13 @@
import URL from 'Common/Types/API/URL';
import Email from 'Common/Types/Email';
import { JSONFunctions, JSONValue } from 'Common/Types/JSON';
import { JSONFunctions, JSONObject, JSONValue } from 'Common/Types/JSON';
import Typeof from 'Common/Types/Typeof';
export default class LocalStorage {
public static setItem(key: string, value: JSONValue | Email | URL): void {
if (typeof value === Typeof.Object) {
// if of type jsonobject.
value = JSON.stringify(JSONFunctions.serializeValue(value as JSONValue));
value = JSON.stringify(JSONFunctions.serializeValue(value as JSONValue) as JSONObject);
}
localStorage.setItem(key, value as string);
}

View File

@ -295,7 +295,7 @@ export default function (
}
const errorCode: $TSFixMe =
typeof error === 'number' ? error : 1;
typeof error === Typeof.Number ? error : 1;
process.exitCode = errorCode;
return error;