Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[import/no-duplicates] false-positive "imported multiple times" in TS #2855

Closed
echocrow opened this issue Aug 9, 2023 · 2 comments
Closed

Comments

@echocrow
Copy link

echocrow commented Aug 9, 2023

We're seeing unexpected import/no-duplicates issues for some packages in TypeScript, which seem to happen when the different modules reuse the same, shared definitions under the hood.

For example:

import type {ActionReturn} from 'svelte/action'
import type {Readable} from 'svelte/store'
// ...

Expected behavior:

# No lint validations; these are two different, non-duplicate imports.

Actual behavior:

  1:33  error  '{...}/node_modules/svelte/types/index.d.ts' imported multiple times  import/no-duplicates
  2:29  error  '{...}/node_modules/svelte/types/index.d.ts' imported multiple times  import/no-duplicates

As per the error message, I guess this is related to the fact that both imports have their types defined in a shared, private file. I'm unsure if this is an issue with the svelte packages per-se, but this being flagged by eslint-plugin-import seems like an unexpected bug? It may be noteworthy that the core no-duplicate-imports ESLint rule does not flag this the same way.

Versions:

  • eslint: 8.46.0
  • eslint-plugin-import: 2.28.0
  • svelte: 4.1.2

A sample repo can be found here with the bare TypeScript & ESLint config.

@ljharb
Copy link
Member

ljharb commented Aug 9, 2023

This is indeed because the TS resolver maps them to the same file. no-duplicate-imports does no resolution, so it doesn't run into this problem (but it misses many other instances as a result).

I'm traveling atm but I believe there may be an existing issue about this.

@echocrow echocrow changed the title [import/no-duplicates] false negative "imported multiple times" in TS [import/no-duplicates] false-positive "imported multiple times" in TS Aug 10, 2023
@echocrow
Copy link
Author

echocrow commented Aug 10, 2023

there may be an existing issue about this.

Apparently I did not search hard enough yesterday; looks like #1479 already talks about the same issue, my bad!

I mean

  #2855  warning  'issues/1479' reported multiple times  issues/no-duplicates

Closing as duplicate. Happy to cross-post the repro if of any value!

@echocrow echocrow closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants