Skip to content

Commit

Permalink
Add omitReturnType
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaoumov committed Sep 14, 2024
1 parent 6913019 commit 4b31859
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Function.ts
Original file line number Diff line number Diff line change
@@ -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<Args extends unknown[]>(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<Args extends unknown[]>(fn: (...args: Args) => Promise<unknown>): (...args: Args) => Promise<void> {
return async (...args: Args) => {
await fn(...args);
};
}

0 comments on commit 4b31859

Please sign in to comment.