Skip to content

Bug: [typedef] false positive with deep array destructuring #5233

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

Closed
4 tasks done
sashaqred opened this issue Jun 23, 2022 · 0 comments · Fixed by #5311
Closed
4 tasks done

Bug: [typedef] false positive with deep array destructuring #5233

sashaqred opened this issue Jun 23, 2022 · 0 comments · Fixed by #5311
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sashaqred
Copy link

sashaqred commented Jun 23, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.6.4&sourceType=module&code=JYOwLgpgTgZghgYwgAgGIHt3IN7IFDLIBGcUAXMgM5hSgDmA3HgL554D07yAygBboBXADYATYigTooUCAjAAaYgLDIhoSFCr8A7sm2kQ9PDAEg5wdCFXo6qYFGoAhUgAoA2rhKbmAXQoZ0Nx8AShwCZEkQSnQhCAA6IRsXL2CmVg4uPkFRcQipGTlFImVVdWgtdF19KEMQOmNTc0trW3snUgBJEAB5MF5oAHU4AE93T1JkXwo3AJCwwkjo2ISklLS2Th5+YTEiCXzZBSUVNXByyh09AyNFlTc3Lx8-Khp6IKDkAF5ke4ByL1+TzYZVgiBQABEIBAAA4BebIOAUbDhQhEJEowgRfyYJiYybhVjpTYDYB9ZAgCDUCBidBEABWh0oeikAGsmTBQBA8LccIjsGjsAgyPzSGQvABGZhS5gUSEwuHfbB8gVCkXkf6kX7S5gMIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6I0gE0QDN0wA2uGw4A7gENoTSABphIrCKU5J0cYQAiKfHDL5YVJgHN+O2IjnLlkVQHtRABUniAtonyJopuBflWcbi4ARp4AapKU4kFIWmTwzviUttIYZr7+IpC2QQBWiHpayGZ6BswmqT6WGTjEzm4eXhXmVdWQxNC2pNBEsfFqicnezX7+kABuEVEx+X3iAylgaS0Z45PRiL0JSUwAkkZMttCIAGKwTHrbQ4gjYAC+fgC6wve3QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYwAviNUA

Repro Code

interface Foo { 
  bar: string;
}

// Should be correct, but linter show warning
function logFirstBar([{ bar }]: Foo[]) {
  console.log(bar);
}

// Should be correct, but linter show warning
function logFirstBarInOtherWay([{ bar }]: [Foo]) {
  console.log(bar);
}

// Should be correct, but linter show warning
const [[bar]]: string[][] = [['bar']]

interface DeepFoo {
  a: {
    b: {
      c: Foo;
    }
  }
}

// With nested objects works fine
const {a:{b:{c:{bar:bar1}}}}: DeepFoo = {a:{b:{c:{bar:'bar'}}}};

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  "rules": {
    "@typescript-eslint/typedef": [
      "warn",
      {
            "arrayDestructuring": true,
            "arrowParameter": true,
            "memberVariableDeclaration": true,
            "objectDestructuring": true,
            "parameter": true,
            "propertyDeclaration": true,
            "variableDeclaration": true,
            "variableDeclarationIgnoreFunction": true
      }
    ]
  }
};

tsconfig

No response

Expected Result

I expected that nested destructuring of arrays with types (like [{ bar }]: Foo[]) wouldn't throw the error "Expected a type annotation" on lines 6, 11, and 16.

Actual Result

There were errors "Expected a type annotation" on the lines 6, 11, and 16

Additional Info

Similar issue connected with object restructuring #4725

Versions

package version
@typescript-eslint/eslint-plugin 5.29.0
@typescript-eslint/parser 5.29.0
TypeScript 4.6.3
ESLint 8.18.0
node 16.14.2
@sashaqred sashaqred added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 23, 2022
@sashaqred sashaqred changed the title Bug: [typedef] false positive with array destructuring Bug: [typedef] false positive with deep array destructuring Jun 23, 2022
@JoshuaKGoldberg JoshuaKGoldberg added good first issue Good for newcomers accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jun 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants