8000 Bug: [no-unnecessary-condition] does not report unnecessary default value during object destructuring · Issue #10082 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: [no-unnecessary-condition] does not report unnecessary default value during object destructuring #10082

@TkDodo

Description

@TkDodo

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.5.2&fileType=.ts&code=GYVwdgxgLglg9mABAYTgWwA4IKZigCgG9Fg45EBeRARkQF8AuRY0uJsENAI2wCd6AlMwBQiRL2xQQvJKwDcwusKA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0yHJgBNK%2BSpPRRE0aB2iRwYAL4gtQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

function Component({ foo = 1 }: { foo: number }) {
  return foo;
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-unnecessary-condition": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I would expect a lint error here form no-unnecessary-condition because the default value assignment can never be reached, given that foo is mandatory in the object

Actual Result

no error shown

Additional Info

The rule correctly reports an error when nullish coalesce is used instead:

function Component2(props: { foo: number }) {
  const foo = props ?? 1

  return foo
}

Unnecessary conditional, expected left-hand side of ?? operator to be possibly null or undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existslocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0