You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionone(){constfoo={a: 1,b: 2};// 'a' is declared but never usedconst{a, ...bar}=foo;console.log(bar);}functiontwo(){constfoo={a: 1,b:2};// '_' is declared but never usedconst{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.
The text was updated successfully, but these errors were encountered:
DanielRosenwasser
changed the title
noUnusedLocals and removing properties with object spread destructuring
noUnusedLocals and removing properties with object rest destructuring
Sep 21, 2017
TypeScript Version: 2.1.4
Code
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 frombar
. With--noUnusedLocals
enabled, we get a warning thata
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.The text was updated successfully, but these errors were encountered: