diff --git a/src/verifyAndStoreOptionValue.ts b/src/verifyAndStoreOptionValue.ts index c341cf0..4db5ab9 100644 --- a/src/verifyAndStoreOptionValue.ts +++ b/src/verifyAndStoreOptionValue.ts @@ -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(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); }