Skip to content

Bug: [no-redundant-type-constituents] Buggy usecases #11810

@KieranP

Description

@KieranP

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=PTAECECcHsGsFMB2oDEBGAUPAHgB2pAC6gCWih8kAZgIYDG8oAKgJ67wCCoA3qAPokAJgH4AXKADOhSGQDmoAL5Y8BYoTaNW7cKAC8zDVwBkPUPyHipMxPKUYQEGAmQoATBioBXRHUIloyBLQALbwhAAWcgAUAG40ADae8OLQAEYAVvC%2BoAA%2BoGmZvgDaALoAlDwYZg5MAPIAIrUYdg5QcEioAMwe3r7%2ByMHQdLAAYmF04VGp0IIs4hyQkDQs4J5UVJS5EPFpWwCiiwRbBVnEeVZyW4ie8fF6oNe3FdxVoDUNTUpAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1ukQBNYmvAIYtaRUrTIcmyfJXyxELVBkiJo0DtEjgwAXxB6gA&tsconfig=N4XyA&tokens=false

Repro Code

// Broken #1
export interface TypeA { _id?: string }
export type TypeB = TypeA & {  _id: string }

// Broken #2
function something(value: object | object[]) {
  // TODO
}

// Broken #3
function mockFetch(body: ArrayBuffer | Blob | Error | object | string | null = null) {
  // TODO
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-redundant-type-constituents": "error"
  },
};

tsconfig

{}

Expected Result

All the examples in the repo should be fine, they don't duplicate types

Actual Result

All three examples are broken:

  • Example 1 doesn't like _id replacing _id?
  • Example 2 doesn't like union object | object[] (two different types...)
  • Example 3 doesn't like Error, becaue it's a type of object, even though the two should be distinct

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