Skip to content

Analyze published type dependencies (resolve #1909) - #1912

Open
webpro wants to merge 4 commits into
mainfrom
issue-1909-exact-type-dependencies
Open

Analyze published type dependencies (resolve #1909)#1912
webpro wants to merge 4 commits into
mainfrom
issue-1909-exact-type-dependencies

Conversation

@webpro

@webpro webpro commented Jul 27, 2026

Copy link
Copy Markdown
Member

Resolves #1909. Implements the emitted-declaration analysis originally requested in #248.

Type-only imports that end up in a package's emitted declaration files are part of its public API. Consumers resolve them from their own dependency tree, so the referenced packages must be in dependencies, while strict mode used to expect all type-only imports in devDependencies.

Knip now analyzes the published type surface of non-private workspaces. Entry declarations are taken from types/typings, the declaration next to main, the index.d.ts fallback, exports (with types condition precedence, wildcard patterns and null subpath exclusions) and typesVersions. The declaration graph is walked from there, including triple-slash references and relative and self-name imports.

External packages referenced by this graph count as production usage:

  • In strict mode they are reported at their declaration file location when only in devDependencies or missing.
  • Untyped packages map to their installed or declared @types/* counterpart, so the report names the package consumers actually need.
  • Resolution follows the consumer view: .ts and .js specifiers in emitted declarations resolve to the matching .d.ts via extension aliases, and the author's tsconfig paths do not apply (the source graph still uses them).

If declaration output has not been built, Knip does not guess from source imports. The walk is bounded to declarations reachable from the published entry points; on this repository it adds about 35ms.

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@1912
npm i https://pkg.pr.new/@knip/language-server@1912
npm i https://pkg.pr.new/@knip/mcp@1912

commit: 1504998

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploying knip with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1504998
Status: ✅  Deploy successful!
Preview URL: https://7fdb5b3e.knip.pages.dev
Branch Preview URL: https://issue-1909-exact-type-depend.knip.pages.dev

View logs

@webpro
webpro force-pushed the issue-1909-exact-type-dependencies branch from c5e52e9 to 08aa075 Compare July 27, 2026 20:25
@webpro
webpro marked this pull request as ready for review July 29, 2026 07:00
@lishaduck

Copy link
Copy Markdown
Contributor

Hey, I was planning on giving this a shot, someday! What's up with everybody taking my issues? (jk)

Whoooooowhooooo! Thanks Lars! This is🔥 🔥 You've made my day and I just woke up! (Ok I should go so I can get a chance to use it but I just had to show some appreciation here.)

@webpro

webpro commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Thanks Eli. That is all much appreciated, and it means a lot coming from a true power user!

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.

💡 Option to treat type-only imports in production code as production dependencies

2 participants