🎨 Add types

This commit is contained in:
C-3PO 2018-10-25 07:44:02 +02:00
parent 60ad737f6f
commit 102e8df598
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -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);
}