I have a specific function type that is capable of returning either void
or Promise<void
:
export type CommandHandler = (values: CommandValues) => void | Promise<void>;
Currently, I am attempting to utilize this function type in a void function:
export const handler = (values: CommandValues): CommandHandler => {
console.log(`hello ${values.name}`);
};
However, an error message is being displayed regarding the usage of CommandHandler
:
The function must return a value as it's declared type is neither 'undefined', 'void', nor 'any'.
This situation has left me puzzled. I have clearly specified in the type that the function can be of type void
. So, why is there an issue?
Based on my understanding, there should not be any errors due to how I've defined the function.