Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

noUnusedLocals and removing properties with object rest destructuring #12766

Copy link
Copy link
@jkillian

Description

@jkillian
Issue body actions

TypeScript Version: 2.1.4

Code

function one(){
  const foo = {a: 1, b: 2};
  // 'a' is declared but never used
  const {a, ...bar} = foo;
  console.log(bar);
}

function two(){
  const foo = {a: 1, b:2};
  // '_' is declared but never used
  const {a: _, ...bar} = foo;
  console.log(bar);
}

Expected behavior:
In example one, it's debatable to me if a should be marked as unused. I propose not marking a variable unused if there's an object spread in the same destructuring. This is because currently, object spreads are the only way to get typed removal of object properties. (Mapped types can let you pick properties, but not let you choose properties to remove, so we can't type something like _.omit yet)

In example two, _ should not be marked as unused.

Actual behavior:
In example one, we have no intention of using a, we're only interested in removing it from bar. With --noUnusedLocals enabled, we get a warning that a is declared but never used. This is debatably correct behavior (see above).

In example two, even when we bind it to the name _, we still get an unused local warning.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.