the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1047:

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.

TS1047

A rest parameter cannot be optional.

Marking a parameter optional (?) indicates that it could be undefined, but when using the rest token (...) indicates that if there are no additional arguments being passed, parameter will simply be set to an empty array. Therefore these tokens are incompatible:

function test(...args?: any[]) {}

Fix: Remove optional token.

Remove the ? token:

function test(...args: any[]) {}