Typescript: Add a 'Replace unused destructured parameter with _' quick fix

Created on 8 Jul 2019  路  4Comments  路  Source: microsoft/TypeScript

From https://github.com/microsoft/vscode/issues/76583

TypeScript Version: [email protected]


Search Terms:

  • quick fix
  • remove destructuring
  • parameter
  • function

Code

function f({x}, y) { return y; }

Trigger quick fixes on {x}

Bug:
A quick fix which removes the destructing is returned, but there is no quick fix to convert the first paramter to a _. Replacing a parameter with _ is available for normal parameters:

function f(x, y) { return y; }
Bug Rescheduled

Most helpful comment

@mjbvz seems like the OP is a complaint that we broke their code by observably changing the function parameter ordering

Changing { x } to _ has observable runtime effects (calling with null no longer throws, for example). We should change it to { } and leave it alone after that; I don't see any benefit to changing it to _ - it just creates new scope pollution

All 4 comments

@mjbvz seems like the OP is a complaint that we broke their code by observably changing the function parameter ordering

Changing { x } to _ has observable runtime effects (calling with null no longer throws, for example). We should change it to { } and leave it alone after that; I don't see any benefit to changing it to _ - it just creates new scope pollution

Perhaps related: #32196

function f({ x }, y) { return y; }

For the first parameter should be two quick-fix options

  • Remove destructuring
  • Remove unused declaration for: 'x'?

@RyanCavanaugh Is it true?

What about the following case?

function f({ x, x1, x2 }, y) { return y; }

I think it should swap from singular to all available to remove:

  • Remove unused declaration for: 'x'?

to

  • Remove unused declarations: 'x, x1, x2'?

and the remove destructuring should stick around

Was this page helpful?
0 / 5 - 0 ratings