Skip to content

Bug: [no-useless-default-assignment] False positive when defaulting parameter to undefined #11847

@doberkofler

Description

@doberkofler

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.9.2&fileType=.tsx&code=GYVwdgxgLglg9mABAWwJ4DFzXmAFABwEYAuRAZygCcYwBzAGkXwCZSwRkAjAU0sQB9E4ACbdgNbsMQBeIWFHiwkgJSIA3gFgAUIkQQEZOABtuAOiNxaBQoxbKA3NoC%2B27WkyRYCXAHJCPh20gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYkACAXAngA4oDG0AlobgLQrzkB2uA9AwPbWzKJLLLUATRADMAhghqi%2B5AOYMAtoibooiaNDbRIAXxDagA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

function myFunction(p1: string, p2: number | undefined = undefined) {
  console.log(p1, p2);
}

myFunction('1');

ESLint Config

module.exports = {
  "rules": {"@typescript-eslint/no-useless-default-assignment": "error"}
}

tsconfig

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

Expected Result

This use should get flagged.

Actual Result

When removing the default, typescript will reports the error 2554: Expected 2 arguments, but got 1. 5:1 - 5:11

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: 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