Skip to content

Instantly share code, notes, and snippets.

@eamonnboyle
Created March 23, 2021 19:42
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 eamonnboyle/4e3d40aedb7c25ed70b352ae8f34a296 to your computer and use it in GitHub Desktop.
Save eamonnboyle/4e3d40aedb7c25ed70b352ae8f34a296 to your computer and use it in GitHub Desktop.
Variadic Function in Middle Position
function assertAreEqual(...args: [number, number, ...number[], string]): void {
const [firstValue, ...remaining] = args.slice(0, args.length - 1) as number[];
const message = args[args.length - 1] as string;
for (const value of remaining) {
if (firstValue !== value) throw new Error(message);
}
}
assertAreEqual(1, 1, 1, 1, "They're not the same");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment