You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The scenario I am seeing is that when a namespace is imported via import * as ns and that namespace is created via re-exporting other modules then there is a false positive on those re-exported modules being unused exports.
In my example reproduction, there are three subfolders as follows:
ns-not-reexported: This folder contains an index.ts file which directly exports two named exports - apple and orange.
ns-named-reexported: This folder contains files named apricot.ts and peach.ts which individually export named apricot and peach. These are then re-exported as named exports in the folder's index.ts.
ns-default-reexported: This folder contains files named blueberry.ts and pear.ts which export default blueberry and pear respectively. These default exports and then re-exported as named exports in the folder's index.ts.
In the root folder, there is an index.ts which imports each of these three subfolders using import * as ns syntax and then simply does a console.log of each of those. Based upon my understanding of the namespace import heuristic, this should result in no unused exports during knip's validation.
The namespace in the ns-not-reexported folder is not reported as an unused export. However, the namespaces in the ns-default-reexported and ns-named-reexported folders are reported as unused exports. It seems that the re-exporting process is causing those to be missed.
Thanks for reproduction, looks clear. There's quite a few cases covered in re-exports-* fixture folders, but apparently this one is missing indeed. To be continued.
I've created a reproduction at https://github.com/shawnmcknight/knip-import-exported-ns.
The scenario I am seeing is that when a namespace is imported via
import * as ns
and that namespace is created via re-exporting other modules then there is a false positive on those re-exported modules being unused exports.In my example reproduction, there are three subfolders as follows:
ns-not-reexported
: This folder contains anindex.ts
file which directly exports two named exports -apple
andorange
.ns-named-reexported
: This folder contains files namedapricot.ts
andpeach.ts
which individually export namedapricot
andpeach
. These are then re-exported as named exports in the folder'sindex.ts
.ns-default-reexported
: This folder contains files namedblueberry.ts
andpear.ts
which export defaultblueberry
andpear
respectively. These default exports and then re-exported as named exports in the folder'sindex.ts
.In the root folder, there is an
index.ts
which imports each of these three subfolders usingimport * as ns
syntax and then simply does aconsole.log
of each of those. Based upon my understanding of the namespace import heuristic, this should result in no unused exports during knip's validation.The namespace in the
ns-not-reexported
folder is not reported as an unused export. However, the namespaces in thens-default-reexported
andns-named-reexported
folders are reported as unused exports. It seems that the re-exporting process is causing those to be missed.Here is the knip output from my reproduction:
The
apple
andorange
exports are properly identified as being used, but the other four are being flagged as unused.Please let me know if there is anything else I can provide to assist!
The text was updated successfully, but these errors were encountered: