return value as Date;
}
if (isString(value) || typeof value === 'number') {
- return new Date(value!);
+ value = new Date(value as string | number);
+ if (isNaN(value.getTime())) {
+ throw new Error(`Cannot convert to date: ${String(value)}`);
+ }
+ return value;
}
return null;
};
changedValue = parseInt(value as string);
}
if (isNaN(changedValue)) {
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- throw new Error(`Cannot convert to integer: ${value.toString()}`);
+ throw new Error(`Cannot convert to integer: ${String(value)}`);
}
return changedValue;
};
changedValue = parseFloat(value as string);
}
if (isNaN(changedValue)) {
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- throw new Error(`Cannot convert to float: ${value.toString()}`);
+ throw new Error(`Cannot convert to float: ${String(value)}`);
}
return changedValue;
};