Skip to content

Instantly share code, notes, and snippets.

@emkis
Last active June 21, 2023 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emkis/bb56314682300d620e3b5185105aa6ba to your computer and use it in GitHub Desktop.
Save emkis/bb56314682300d620e3b5185105aa6ba to your computer and use it in GitHub Desktop.
A TypeScript version of the callAll function
/* eslint-disable @typescript-eslint/no-explicit-any */
type CallBack<Params extends any[]> = {
(...args: Params): void;
};
export function callAll<Params extends any[]>(...fns: Array<CallBack<Params> | undefined>) {
return (...args: Params) => fns.forEach((fn) => typeof fn === 'function' && fn(...args));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment