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

🐛 False positive unused export #890

Open
6 tasks done
DreierF opened this issue Dec 22, 2024 · 2 comments
Open
6 tasks done

🐛 False positive unused export #890

DreierF opened this issue Dec 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DreierF
Copy link

DreierF commented Dec 22, 2024

Prerequisites

Reproduction url

https://stackblitz.com/edit/github-99dfwi73-hxo2rmv8?file=index.ts

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

Observed behavior
The example produces:

Unused exports (1)
bar  mod1  function  mod1.ts:5:17

while bar is actually used in index.ts.

Expected behavior
No error

@DreierF DreierF added the bug Something isn't working label Dec 22, 2024
@webpro
Copy link
Collaborator

webpro commented Dec 22, 2024

Thanks for the repro. Personally I wouldn't call this "barrel-like", btw.

Either way, it's a bit of an unfortunate case:

  • By default, Knip assumes all members of mod1Exports used because of the default heuristics: https://knip.dev/guides/namespace-imports
  • Then there's --include nsExports but the destructured ...mod1Exports is something Knip is unable to follow further.
  • And there's --include-libs to hand it over to TypeScript internals (which should be documented better for this use case), but even LS.findReferences doesn't find it. You could verify in your IDE with a "Find All References" from export function bar: this won't bring you to it's usage.

@DreierF DreierF changed the title 🐛 False positive unused export for barrel like file 🐛 False positive unused export Dec 22, 2024
@DreierF
Copy link
Author

DreierF commented Dec 22, 2024

Yeah, didn't know a more fitting term for this construct. However IntelliJ is able to follow along this usage path, but it might use an internal heuristic there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants