Skip to content
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

Unused exported type & interface members #910

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

webpro
Copy link
Collaborator

@webpro webpro commented Jan 12, 2025

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: 2b01993

WIP. From: #848 (comment)

TODO:

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

Copy link

pkg-pr-new bot commented Jan 12, 2025

Open in Stackblitz

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

commit: 4b7682c

Copy link

cloudflare-workers-and-pages bot commented Jan 13, 2025

Deploying knip with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4b7682c
Status:🚫  Build failed.

View logs

@webpro webpro force-pushed the feat/unused-exported-type-members branch from 62a5eb8 to 240ae82 Compare January 15, 2025 20:13
@webpro webpro force-pushed the feat/unused-exported-type-members branch from 240ae82 to 718bf1a Compare January 15, 2025 20:14
@tylersayshi
Copy link

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.

@webpro
Copy link
Collaborator Author

webpro commented Jan 24, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants