the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1014:

All diagnostics and fixes are authored in markdown. Propose any changes by editing the markdown. Additional fixes can be added. A preview of the rendered diagnostic will update when changes are made.

Once all proposed changes are made, the Propose button will submit the information and confirm raising the PR.

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
) {}