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

no-unused-vars wrong diagnostic when using destructuring and defaults #687

Closed
lowlighter opened this issue May 8, 2021 · 1 comment · Fixed by #688
Closed

no-unused-vars wrong diagnostic when using destructuring and defaults #687

lowlighter opened this issue May 8, 2021 · 1 comment · Fixed by #688

Comments

@lowlighter
Copy link

lowlighter commented May 8, 2021

const {id, name = id} = {id:"10"} as {[key:string]:string}
console.log(name) //"10"

When using destructuring assignement along with default subsequent values, linter report false positives:

(no-unused-vars) `id` is never used
const {id, name = id} = {id:"10"} as {[key:string]:string}
       ^^
    at \\test.ts:1:7

    hint: If this is intentional, prefix it with an underscore like `_id`

Found 1 problem
Checked 1 file
deno 1.9.2 (release, x86_64-pc-windows-msvc)
v8 9.1.269.5
typescript 4.2.2

Edit: Actually maybe it is actually expected to do the following?

const {id:_id, name = _id} = {id:"10"} as {[key:string]:string}
console.log(name) //"10"
@magurotuna
Copy link
Member

Thanks for reporting! Looks like a little bit tricky code that I've never seen before, but should not trigger the lint error.
I've fixed it in #688.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants