pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

doesn't work as intended when using `export * from "./abc" ` statement #286

Open demonhue opened 1 year ago

demonhue commented 1 year ago

There are 3 files in one folder a.ts, b.ts and c.ts

a.ts

let a = 5, b = 10;
export {a,b};

b.ts

export * from "./a.ts"

c.ts

import {a} from "./b.ts"

then it shows that there is an unused export in b.ts named b even though there is no export named b in b.ts

AivarasBartasevicius commented 1 year ago

You are exporting both a and b from b.ts because of the "*",

1 option: b.ts was export * as aStuff from "./a.ts" and c.ts was import { aStuff } from "./b.ts"

2 option: b.ts was export a from "./a.ts" and c.ts was import { a } from "./b.ts"

both options should work. of course in option 2 the error then would say that a.ts has unused b, and in option 1 I image it would work, but you would be hiding that b is unused act.

jtbandes commented 1 year ago

I have the same issue, and I also notice that the reported location (line number) is wrong. It corresponds to the line number of the original export, not the line number of the export *. This makes it hard/impossible to use a // ts-unused-exports:disable-next-line comment to work around the issue.

I reported the same issue in ts-prune https://github.com/nadeesha/ts-prune/issues/141 and that was never resolved either.