🎨 Add types
This commit is contained in:
parent
60ad737f6f
commit
102e8df598
1 changed files with 3 additions and 3 deletions
|
@ -2,7 +2,7 @@ import IOption from './interfaces/IOption';
|
||||||
import IState from './interfaces/IState';
|
import IState from './interfaces/IState';
|
||||||
|
|
||||||
/** Calls the given function, and in case of an error, uses the given function to provide a custom description for the error message. */
|
/** Calls the given function, and in case of an error, uses the given function to provide a custom description for the error message. */
|
||||||
function execWithCustomError(func: (...args: any[]) => any, showError: (error: Error) => string) {
|
function execWithCustomError<ReturnType>(func: (...args: any[]) => ReturnType, showError: (error: Error) => string): ReturnType {
|
||||||
try {
|
try {
|
||||||
return func();
|
return func();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -30,9 +30,9 @@ export default function verifyAndStoreOptionValue({
|
||||||
requiredOptions: IState['requiredOptions'],
|
requiredOptions: IState['requiredOptions'],
|
||||||
}): void {
|
}): void {
|
||||||
//Verify value for correctness
|
//Verify value for correctness
|
||||||
const verifyValue = execWithCustomError(verify.bind(null, value), (error) => `Invalid value set for option "${option}", the validation of "${value}" failed: ${String(error)}`);
|
const verifyValue: boolean = execWithCustomError(verify.bind(null, value), (error) => `Invalid value set for option "${option}", the validation of "${value}" failed: ${String(error)}`);
|
||||||
if (verifyValue !== true) {
|
if (verifyValue !== true) {
|
||||||
const customMessage = execWithCustomError(message.bind(null, value), (error) => `Invalid value set for option "${option}": "${value}". Could not create custom error message: ${String(error)}`);
|
const customMessage: string | undefined = execWithCustomError(message.bind(null, value), (error) => `Invalid value set for option "${option}": "${value}". Could not create custom error message: ${String(error)}`);
|
||||||
if (customMessage !== undefined && customMessage !== '') {
|
if (customMessage !== undefined && customMessage !== '') {
|
||||||
throw new Error(customMessage);
|
throw new Error(customMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue