knip icon indicating copy to clipboard operation
knip copied to clipboard

Unused exported type & interface members

Open webpro opened this issue 1 year ago • 4 comments

This PR introduces --include typeMembers to find unused members of exported types and interfaces.

Docs: https://feat-unused-exported-type-me.knip.pages.dev/guides/type-members.

See below to install latest version through pkg.pr.new.

Dogfooded knip --include typeMembers --fix: 2b019931085da943b3db9725fbfec64b21c5b42a

WIP. From: https://github.com/webpro-nl/knip/pull/848#issuecomment-2585735560

TODO:

  • [x] Improve docs and explain better what members exactly are and are not analyzed
  • [x] Remove members with --fix
  • [ ] Mileage

webpro avatar Jan 12 '25 21:01 webpro

Open in Stackblitz

npm i https://pkg.pr.new/knip@910

commit: 897448b

pkg-pr-new[bot] avatar Jan 12 '25 21:01 pkg-pr-new[bot]

Deploying knip with  Cloudflare Pages  Cloudflare Pages

Latest commit: 897448b
Status: ✅  Deploy successful!
Preview URL: https://a557c772.knip.pages.dev
Branch Preview URL: https://feat-unused-exported-type-me.knip.pages.dev

View logs

This sounds like a helpful thing to warn on.

At the same time, it seems perfectly valid to have unused type members for things like the result of an external REST api request. I'd type out all members of the expected response and maybe not use all of the fields at first.

tylersayshi avatar Jan 24 '25 17:01 tylersayshi

Iteration speed is definitely a thing to consider, yet could be mitigated using local JSDoc tags or config e.g. ignore: ["src/{api,generated}/**"] to (temporarily) exclude files or parts of the codebase. But won't suit everyone, takes a little bit of extra work/config. In the end the issue type is opt-in to begin with.

webpro avatar Jan 24 '25 17:01 webpro

There are still bugs atm, but mostly closing due to added scope/complexity.

webpro avatar Apr 08 '25 07:04 webpro