knip icon indicating copy to clipboard operation
knip copied to clipboard

Exports previously legitimately reported as unused are no longer reported

Open neelmraman opened this issue 1 year ago • 1 comments

Hi, after seeing that #697 was closed, I updated knip in the repro for that issue (here) to verify.

The behavior on v5.23.0 was that a, b, c, and d were reported as unused while the other two exports that used multiline exports were not reported (even though they were also unused). The new behavior on v5.23.1 is that none of the exports are reported as unused.

neelmraman avatar Jun 27 '24 23:06 neelmraman

There's a few things to this one. We're only talking about the combination of:

  • ignoreExportsUsedInFile: true
  • The export { id } notation

Unfortunately, internally when using the TypeScript AST nodes there's a big difference between these notations:

export const id = 1;
const id = 1;
export { id };

With the latter syntax, I couldn't find a reliable way to detect whether id was used more often or not within the same module. That's why I've opted for the stability of assuming export { id } is referenced (which technically could be argued it is, but it could be only the declaration, not other usage).

So this is the situation now, until we've found a reliable way to do it better.

Additional notes:

  • Usually ignoreExportsUsedInFile is used only for types, since values don't need to be exported. E.g. "ignoreExportsUsedInFile": { "interface": true, "type": true }
  • The former syntax doesn't have this issue, so purely from a Knip perspective that would be recommended.

webpro avatar Jun 28 '24 04:06 webpro

Closing this issue as part of a general cleanup to keep this project sustainable and optimize my time working on it. If you think this is inappropriate or if there is no workaround and you feel stuck, feel free to open a new issue. Thanks for your understanding.

webpro avatar Aug 10 '25 07:08 webpro