knip icon indicating copy to clipboard operation
knip copied to clipboard

🐛 Imports in `declare module` are not detected (TypeScript)

Open fregante opened this issue 1 year ago • 1 comments

No repro

Prerequisites

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:

fregante avatar Feb 21 '25 06:02 fregante

Here's a smaller repro that doesn't make use of @types packages, to avoid confusion:

Download

repro.zip

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 dependencies is expected, it doesn't exist.
  • Unused dependencies is 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.

fregante avatar Feb 21 '25 09:02 fregante

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