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
TypeScript Namespace - Unsed exported constants not detected #615
Comments
In the meanwhile, while trying to get rid of some namespaces, I realized this. If I convert the above code, it still does not recognize it as being unused. Which I assume is related on an abstract level? export const Foo {
UNUSED_VARIABLE: "bar"
} I tried to use |
Only top-level exports are considered. I guess an exception should be made for namespaces indeed. If by any chance you'd like to give it a shot you could start here: https://github.com/webpro/knip/blob/main/packages/knip/src/typescript/getImportsAndExports.ts#L279-L289 Now that I look at it, this looks oddly unfinished: https://github.com/webpro/knip/blob/main/packages/knip/fixtures/module-block/types.ts Otherwise I'll pick it up at some point. The second example is not a |
I'm having a VERY similar problem which has nothing to do with TS namespaces. |
@AndreaPontrandolfo To be quite honest, I'm not sure how that's helping out @weilbith and/or this project here? The title of this issue is "TypeScript Namespace". Feel free to open a new issue with more details, such as a reproducible test case. Or, indeed, downgrade. |
@weilbith Could you please create a minimal reproduction of the issue so I can see how things are imported and exported, including relevant TS config? I want to make sure the fixes are correct without introducing unexpected/breaking changes (or decide what needs to go into a next major if it is). |
Hmm. I struggle to do so. 🙈 $ mkdir /tmp/knip-test-namespace
$ cd /tmp/knip-test-namespace
$ npm init
$ npm add --save-dev typescript knip
$ npx tsc --init Creating at least two source files to create the relationship of an used and unused export:
export namespace Foo {
export function bar() {}
export function baz() {}
}
import { Foo } from "./namespace"
Foo.bar() Running now |
Aloha
I'm aware of the following unused/dead code in my legacy project, but
knip
does not detect it. I know version 5 added some "namespace" support, but this does not work unfortunately.I can verify with other language tools, but even with a plain search that this
UNUSED_VARIABLE
is nowhere used in the whole repository. Unfortunately knip, as great as it is, does not detect this.Is that maybe already known? I couldn't find an related issue. Sorry, if there is one.
PS:
Please don't ask me about the above code. 😑
The text was updated successfully, but these errors were encountered: