Skip to content

Bug: [consistent-type-imports] False negatives when type name also refers to a local value #8315

Open
@haskellcamargo

Description

@haskellcamargo

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.3.3&fileType=.tsx&code=PTAEAEBcGcFoFMAeAHeBjSCBOWD2XRZQAVAC3lAFtcATAVwBsKbd5oA7AcklCQEtokADSgARnR6RSA0DPa4eWeEwBuAQ3aQAdACg%2BlZPh4BvUAAUGatPFK4GNeAQC%2BoAGZ5KoTskvXb9x04Abh0dJEMsSQBPVFAAYVx2Vz4Ac1AAXlBjHVBQHysbOwcsAC5zX0KArBCnUJBQAEFQaCjKUTtQAHc%2BKVApCmg1Sgp2IYo1aD7yPpj4HVc6dgw%2BRPKC-2KACgBKLJzQJUg6LHZQdkYGGrqwAFVoPnY0-tAGXDQ1BmbW9s%2BJ0DVQOoGHQ5uEjG5FstVgBZNQPHZ7XKHY6nAA8FnWRUcoGAAD4rkA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6MgeyeUuX0Ra0ipWpQC2xDtHyoMkRNGhTI4MAF8QaoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

// @ts-expect-error - The module doesn't exist, but this is not relevant.
import { Placeholder } from 'placeholder';

export type Config = {
  // Using it only as a type
  placeholder: Placeholder;
}

// A symbol with the same name as the type
function Placeholder() {
  return null;
}

// Using the local symbol as a value
export function Main() {
  return <Placeholder />;
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/consistent-type-imports": "error"
  }
}

tsconfig

No response

Expected Result

It should report an error because the actual import is only used as a type. Instead no error is reported.
TSC accepts types with the same name as local values. Babel with the TypeScript preset throws an error due to having a duplicate identifier as it is unable to determine that the import will be dropped during compile-time.
There's also changes coming to TypeScript 5.4 that introduces errors when type-only imports conflict with local values.

Actual Result

No errors shown.

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-plugin

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy