Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noUnusedLocals and removing properties with object rest destructuring #12766

Closed
jkillian opened this issue Dec 8, 2016 · 1 comment
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jkillian
Copy link

jkillian commented Dec 8, 2016

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.

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 8, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Dec 8, 2016
sheetalkamat added a commit that referenced this issue Dec 8, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 9, 2016
@jkillian
Copy link
Author

jkillian commented Dec 9, 2016

Thanks for the quick fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants