the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

TS1014

A rest parameter must be last in a parameter list.

It is not possible to have multiple rest parameters, or have rest parameters before regular parameters since they consume all other arguments.

function printf(...args: any[], format: string) {}
// or
function callMany<T extends any[]>(
  ...functions: ((...args: T[]) => void)[],
  ...args: T
) {}

Fix: Move rest parameter to the end

Consider moving the rest parameter to the end:

function printf(format: string, ...args: any[]) {}

Fix: Accept an array

Consider accepting an array of arguments:

function printf(args: any[], format: string) {}

function callMany<T extends any[]>(
  functions: ((...args: T[]) => void)[],
  ...args: T
) {}