Chore(front): Add more typeguards (#2136)

* Chore(front): Add more typeguards

Co-authored-by: Benjamin Mayanja V <vibenjamin6@gmail.com>
Co-authored-by: KlingerMatheus <klinger.matheus@gitstart.dev>

* Remove source map generation to avoid warnings

---------

Co-authored-by: Benjamin Mayanja V <vibenjamin6@gmail.com>
Co-authored-by: KlingerMatheus <klinger.matheus@gitstart.dev>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
gitstart-twenty
2023-10-24 10:26:47 +03:00
committed by GitHub
parent 80d558559f
commit 5acafe2fc6
29 changed files with 82 additions and 87 deletions

View File

@ -1,3 +1,5 @@
import { isNull, isNumber, isString } from '@sniptt/guards';
import { logError } from './logError';
const DEBUG_MODE = false;
@ -11,13 +13,13 @@ export const canBeCastAsIntegerOrNull = (
return false;
}
if (typeof probableNumberOrNull === 'number') {
if (isNumber(probableNumberOrNull)) {
if (DEBUG_MODE) logError('typeof probableNumberOrNull === "number"');
return Number.isInteger(probableNumberOrNull);
}
if (probableNumberOrNull === null) {
if (isNull(probableNumberOrNull)) {
if (DEBUG_MODE) logError('probableNumberOrNull === null');
return true;
@ -29,7 +31,7 @@ export const canBeCastAsIntegerOrNull = (
return true;
}
if (typeof probableNumberOrNull === 'string') {
if (isString(probableNumberOrNull)) {
const stringAsNumber = +probableNumberOrNull;
if (isNaN(stringAsNumber)) {
@ -54,7 +56,7 @@ export const castAsIntegerOrNull = (
throw new Error('Cannot cast to number or null');
}
if (probableNumberOrNull === null) {
if (isNull(probableNumberOrNull)) {
return null;
}
@ -62,11 +64,11 @@ export const castAsIntegerOrNull = (
return null;
}
if (typeof probableNumberOrNull === 'number') {
if (isNumber(probableNumberOrNull)) {
return probableNumberOrNull;
}
if (typeof probableNumberOrNull === 'string') {
if (isString(probableNumberOrNull)) {
return +probableNumberOrNull;
}