-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Ensure that @types/*
used in emitted declarations are in dependencies
#248
Comments
Yes, I think Knip can help here. Related to #241. |
Currently Knip just expects So yeah. the issue is that More refs:
To be continued |
Any chance you could whip up a repro? One or more cases would be very helpful. Running in strict production mode should "fail" now. |
Spent half an hour trying to understand why I can't get my repro to fail, when I realized that Knip actually never complained 😂 Knip is fine with |
Updated the repro to also include a case without |
@alecmev you can often take advantage of duck typing to sever If you know examples of popular npm packages that bundle TS types and put |
@danvk Do you know of examples or ways to basically replace the transitive type deps with a dummy? Just to avoid the |
What I meant was more replacing: import {SomeType} from 'big-complicated-package';
export function foo(obj: SomeType) { ... } with: export interface SomeType {
just: string;
fields: number;
you: boolean;
careAbout: Date;
}
export function foo(obj: SomeType) { ... } By inlining just the portion of the type you actually care about, you broaden your API and get to sever a dependency. (You should test that your version of the type is compatible with the canonical one in your tests, but then you're in For severing transitive dependencies without code changes, that's a messy topic and I have a few thoughts :)
|
Thanks a lot for chiming in and the references, Dan! For simple types replacing external types is fine, but I guess in many cases this isn't very ergonomic or sustainable. Just stumbled upon https://github.com/timocov/dts-bundle-generator. Interesting project! Has a few issues that prevents me from using it for Knip yet, but I'll play with it some more and keep watching it. I guess as long as Knip isn't imported and used programmatically (but only used from CLI) I can get away with it. |
Since I haven't had any more reports about this being an issue, I'm going to close it. Separating |
Hmm, I'm not sure, none of the three options seem satisfactory/viable to me:
|
Sorry for two messages, forgot to add:
My suspicion is that most of the time people get lucky and there's a fitting |
No worries! All signals are welcome. Currently I'm just trying to keep some sanity in (the number of) open issues. For this particular issue, the cost/impact does not warrant the outcome (for me; feel tree to take a stab at it). I should definitely add it to the list of known issues: https://knip.dev/reference/known-issues. Sorry I forgot about that. |
I respect that 😉 I do agree that this is somewhat "pedantic" territory. |
I'm not sure if this is in scope of Knip, but it feels like it could be. In a nutshell, if I have a module like this:
And
foo
comes with a corresponding@types/foo
, then I need to make sure that it's actually independencies
. Otherwisebar/dist/index.d.ts
will be broken in any consumer ofbar
that doesn't have@types/foo
in its dependency tree.The complication I'm seeing is determining whether a
@types/*
actually ends up being used indist
. And putting all@types/*
independencies
doesn't make sense, obviously. Does TypeScript have an API of any sort for checking this?More context in this Stack Overflow question.
The text was updated successfully, but these errors were encountered: