From 102e8df5986aea7eaf46319dc112a768350dc8c8 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 25 Oct 2018 07:44:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Add=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/verifyAndStoreOptionValue.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); }