Skip to content

Bug: [no-unsafe-assignment] Misleading error message for object destructuring #11387

Open
@szhsin

Description

@szhsin

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=5.8.2&fileType=.tsx&code=MYewdgzgLgBAZiEMC8MA8AVANAPgBQAmAhlEQFwwYCUKOMeA3jMaVjAJYQCiAtgA5QAnhQCELIjAC%2BVANwAoUJFhNxUlPER4AUgGUA8gDkAdHyIAnCAFM8AcgaSbVWUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZolp9kySgHMmAW0Qt0kRNGgdokcGAC%2BITUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const foo = <T,>(data: T) => ({ data, isEmpty: !data });

const { data } = foo(JSON.parse('{}'));

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unsafe-assignment": "error",
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

If the linter wants to report an unsafe destructuring of any type, the message should clearly indicate it’s due to destructuring from an object, not an array or tuple.

Actual Result

The code produces the following error:

Unsafe array destructuring of a tuple element with an `any` value

data is inferred as any, which makes sense and it's fair for the rule to report that.

What doesn't make sense is the error message — it's an object destructuring, not an array. The message is confusing and makes it sound like a tuple or array is involved, when it's clearly just pulling a property off an object.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinggood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy