Skip to content

Instantly share code, notes, and snippets.

@ruddha2001
Created June 27, 2020 17:05
Show Gist options
  • Save ruddha2001/d581f37d484df14f38fc4c6ef509b09b to your computer and use it in GitHub Desktop.
Save ruddha2001/d581f37d484df14f38fc4c6ef509b09b to your computer and use it in GitHub Desktop.
/**
* Allow only positive numbers, throw error for negative ones
* @param {number} num - Number to test
*/
export const asyncThrowsError = async (num: number) => {
if (num >= 0) return "You are good to go";
throw Error("Negative numbers are not accepted");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment