knip
knip copied to clipboard
🐛 Imports in `declare module` are not detected (TypeScript)
No repro
Prerequisites
- [x] I'm using the latest version
- [x] I've read the relevant documentation
- [x] I've searched for existing issues
- [x] I've checked the list of known issues
- [x] I've read the issue reproduction guide
Reproduction url
Stub issue, I can create a repro if required
Reproduction access
- [x] I've made sure the reproduction is publicly accessible
Description of the issue
npm install react-select react-select-virtualized
I have this in my globals.d.ts file and knip is missing the usage of "react-select":
// Package has no types: https://github.com/guiyep/react-select-virtualized/issues/293
declare module "react-select-virtualized" {
export { default } from "react-select";
// https://deluxe-blancmange-4a5494.netlify.app/#/?id=usage-with-creatable
export { Creatable } from "react-select/creatable";
}
I can confirm that:
- Changing
exports x fromtoimport "react-select"doesn't change the result - Adding
import "react-select"outsidedeclare moduledoes fix it, but that changes how TypeScript interprets the file
Here's a smaller repro that doesn't make use of @types packages, to avoid confusion:
Download
Code
// global.d.ts
declare module "my-lil-error-checker" {
export { isErrorLike } from "serialize-error";
}
Output:
Unused dependencies (1)
serialize-error package.json:4:6
Unlisted dependencies (1)
my-lil-error-checker index.ts
-
Unlisted dependenciesis expected, it doesn't exist. -
Unused dependenciesis the bug/feature request
Like in the original post, adding import "serialize-error" at the top of global.d.ts recognizes the usage of the dependency.
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.