Skip to content

Bug: [no-duplicate-type-constituent] fixer removes undefined from type #9230

@hasakilol

Description

@hasakilol

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://github.com/hasakilol/react-vite/blob/master/src/Test.tsx

Repro Code

Please focus on `Test.tsx` and ignore other source files.

Run `npx eslint --fix src/Test.tsx` in project root dir.

ESLint Config

export default tseslint.config(
  {
    name: 'plugins',
    plugins: {
      ['@typescript-eslint']: tseslint.plugin,
    },
  },
    
  {
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.es2015,
      },
      parserOptions: {
        allowAutomaticSingleRunInference: true,
        project: ['tsconfig.json'],
        tsconfigRootDir: '.',
      }
    },
  },

  {
    name: 'src',
    files: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.mts', 'src/**/*.cts'],
    extends: tseslint.configs.recommendedTypeChecked,
    languageOptions: {
      parser,
      parserOptions: {
        ecmaFeatures: {
          jsx: true
        },
        sourceType: 'module',
      },
      globals: {
        ...globals.browser,
        ...globals.mocha,
        ...globals.jest,
        ...globals.jasmine,
      },
    },
    rules: {
      '@typescript-eslint/consistent-type-imports': 'error',
    }
  },

    
);

tsconfig

No response

Expected Result

import type { Null } from './utils/common.ts'; // Pay attention here
import { Undefined} from './utils/common.ts'; 
import React from 'react';
import { Button } from "antd";

interface TestProps {
  onClick: (
    item?: { a: string; } | typeof Null | typeof Undefined,
    selected?: boolean,
  ) => void;

}

const Test: React.FC<TestProps> = (props) => {
  const {
    onClick,
  } = props;

  return <Button onClick={() => onClick(Undefined, true)}></Button>
};

export default Test;

Actual Result

import type { Null } from './utils/common.ts';
import { Undefined} from './utils/common.ts';
import React from 'react';
import { Button } from "antd";

interface TestProps {
  onClick: (
    item?: { a: string; } | typeof Null  , // Unexpected change here !!!!!!
    selected?: boolean,
  ) => void;

}

const Test: React.FC<TestProps> = (props) => {
  const {
    onClick,
  } = props;

  return <Button onClick={() => onClick(Undefined, true)}></Button>
};

export default Test;

Additional Info

"@typescript-eslint/eslint-plugin": "^8.0.0-alpha.14",
"@typescript-eslint/parser": "^8.0.0-alpha.14",
"@typescript-eslint/scope-manager": "^8.0.0-alpha.14",
"@typescript-eslint/type-utils": "^8.0.0-alpha.14",
"@typescript-eslint/types": "^8.0.0-alpha.14",
"@typescript-eslint/typescript-estree": "^8.0.0-alpha.14",
"@typescript-eslint/utils": "^8.0.0-alpha.14",
"@typescript-eslint/visitor-keys": "^8.0.0-alpha.14",
"typescript-eslint": "^8.0.0-alpha.14",

"eslint": "^9.3.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix: user errorissue was fixed by correcting the configuration / correcting the codelocked 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-pluginplease fill out the templatewe have the processes for good reasons 😔

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions