Created
March 23, 2021 19:42
-
-
Save eamonnboyle/4e3d40aedb7c25ed70b352ae8f34a296 to your computer and use it in GitHub Desktop.
Variadic Function in Middle Position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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