Rest Parameters In TypeScript

[!INFO]-
topic: πŸ¦’ TypeScript
links:

source: TypeScript course by the native web
tags: #permanent-noteΒ #published

Last Modified: =dateformat(this.file.mtime, "MMM. dd, yyyy - HH:mm")


To scale functions properly, you can add additional properties as an array that you spread with …. In JavaScript, this structure is called the rest parameters.

const add = function (left: number, right: number, ...others: number[]): number {
  let sum = left + right;

  for (const other of others) {
    sum += other;
  }

  return sum;
};

console.log(add(2, 3));
console.log(add(2, 3, 4, 5, 6, 7));