From 4b318599928d7065799fa33c0c1b26be6f87db41 Mon Sep 17 00:00:00 2001 From: Michael Naumov Date: Sat, 14 Sep 2024 16:44:53 -0600 Subject: [PATCH] Add omitReturnType --- src/Function.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Function.ts diff --git a/src/Function.ts b/src/Function.ts new file mode 100644 index 0000000..b8abfe9 --- /dev/null +++ b/src/Function.ts @@ -0,0 +1,25 @@ +/** + * Makes a function that calls the original function with the provided arguments and omits the return value. + * + * @typeParam Args - Arguments to be passed to the function. + * @param fn - Function to be called. + * @returns A function that calls the original function with the provided arguments and omits the return value. + */ +export function omitReturnType(fn: (...args: Args) => unknown): (...args: Args) => void { + return (...args: Args) => { + fn(...args); + }; +} + +/** + * Makes an async function that calls the original async function with the provided arguments and omits the return value. + * + * @typeParam Args - Arguments to be passed to the function. + * @param fn - Function to be called. + * @returns An async function that calls the original function with the provided arguments and omits the return value. + */ +export function omitAsyncReturnType(fn: (...args: Args) => Promise): (...args: Args) => Promise { + return async (...args: Args) => { + await fn(...args); + }; +}