Skip to content

Bug: [no-useless-default-assignment] False positives #11846

@arperry

Description

@arperry

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=JYWwDg9gTgLgBAbzgVwM4FMDCBDANrgI2wGMBrOAXzgDMoIQ4ByKdEmRgbgFgAoX4iADtU8ANrYANHAJTicALxNGAXQVNU9dCKiMAdKjC5gMABR7GASm58eA4fAD6IAJ458RMmrRY8hEqRNeODgTADc8ZHQALjhBZBACdChRVUUUqQgwJOwYaAB%2BGO1gQQBzCwUAPjhRXVrw3EiMrKgc6GUJIOrJaVllXiteXhhnLLgABWwWkFQ1MboQYAwAHiQAD0KYKGKSlMoK634hETgHMDpiLVQJqZnFbFRnQTkTMEnsaZjr99Ry%2BSqETp2Y5rGKiBzdBwyE5yRSMACMACYAMwqShqbAAd2wxjgrxu1go1iAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYkACAXAngA4oDG0AlobgLQrzkB2uA9AwPbWzKJLLLUATRADMAhghqi%2B5AOYMAtoibooiaNDbRIAXxDagA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

import { useCallback } from 'react';

const [a, b, c = ''] = 'somestr'.split('.');

const _myCallback = useCallback(
  (value: number[] = [], operator?: string) => [...value, operator],
  [a, b, c]
);

type Params = Promise<{ x: string[] }>;

const _processParams = async (params: Params) => {
  const { x: [_a, _b, _c = '123'] } = await params;
};

ESLint Config

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

tsconfig

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

Expected Result

None of these uses should get flagged under this rule.

Actual Result

"Default value is useless because the (parameter|property) is not optional."

Arrays are assumed to be of indefinite length

const [a, b, c = ''] = 'somestr'.split('.');
const { x: [_a, _b, _c = '123'] } = await params;

These are only useless assignments when the array is of sufficient length.

Something about useCallback makes arg defaults get flagged

(value: number[] = [], operator?: string) => [...value, operator]

This works in isolation, but inside of useCallback, it gets flagged.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething 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