Closed kachkaev closed 3 years ago
Hi @kachkaev thanks for reporting.
I think this could be solved via https://github.com/pzavolinsky/ts-unused-exports/issues/30
TODO:
add unit or itests to capture the above
try implementing #30 if that fixes this issue I suggest this because it is a general solution (and making it optional behaviour avoids breaking change).
@kachkaev if you have the time, it would be great to have your contribution!
Hi @mrseanryan! I think that the proposed ignoreLocallyUsed
option in #30 is not doing quite the same thing. To me, reporting export const a
which could be const a
is a valid feedback, while --allowUnusedTypes
+ export type ...
is a false positive.
Iβm not familiar with the architecture of ts-unused-exports
at this point, so I wonder if detecting symbols that stick out via export type
is at all feasible. From my observations, --allowUnusedTypes
works well already and the only false positives are when there is export type { X } from "./someFile"
.
Happy to try contributing with the unit tests.
I added some broken tests in #181
UPD: Oh wow looks like I fixed it. Neat codebase folks π
Thank you @kachkaev for contributing π
@pzavolinsky we can release this as a patch
:)
First things first: fantastic tool π I tried it in a large project yesterday and found so much dead code!
Iβd like to report one little issue that Iβve noticed. When I add
--allowUnusedTypes
, I still get reports for types that have been re-exported viaexport type { Foo } from "./foo";
. Here is an MWE:Init the project:
Create TypeScript files
Run
ts-unused-exports
without--allowUnusedTypes
Output:
All works as expected.
Run
ts-unused-exports
with--allowUnusedTypes
Output:
Expected output:
In the real scenario, I have functions with React components and interfaces with component props. Re-exports are needed because some components are complex and are therefore put into sub-folders. Having
export type
as an extra line is necessary when the component itself is a default export (itβs not possible toexport * from "./fn2"
in this case).Happy to help with finding a solution, if needed. Thanks again for the tool π