🎨 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';
|
||||
|
||||
/** 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 {
|
||||
return func();
|
||||
} catch (error) {
|
||||
|
@ -30,9 +30,9 @@ export default function verifyAndStoreOptionValue({
|
|||
requiredOptions: IState['requiredOptions'],
|
||||
}): void {
|
||||
//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) {
|
||||
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 !== '') {
|
||||
throw new Error(customMessage);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue