-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Private types are exported #153
Comments
I think this is one of features why On the other hand, this is the one of the oldest feature in Can you please provide a use case when it might be useful? I do understand cases when this is true for classes/functions/enums/any other stuff which affects JS code (and the tool handles this already), but why you want to get the same for interfaces/types? Your users won't be able to import these types and declare variables/arguments with there parameters (I used to use Spotify NodeJS API so time ago and they don't export some of auto-generated types and this was awful experience to use that API, because instead of just importing a type you have to write something like But I don't mind to add a new option to disable this behaviour if there is a real use case for that. |
That's the idea. I don't want them to be able to import them. I sometimes have to write quite long and complex types. To make them more readable and to avoid code duplication, I split those complex types up into smaller helper types. These helper types should not be exported because they are only used to implement the complex type. If the implementation of the complex type changes, I might change/remove the helper types. If people are able to import these helper types, I cannot change/remove them without breaking their code. Put simply, if all types are exported, I have no control over the API of my library. Example: type NodeIdent = { type: Node["type"] };
type NoParentArray<T> = { [K in keyof T]: NoParent<T[K]> };
type NoParentNode<T extends NodeIdent> = { [K in keyof NoParentNodePick<T>]: NoParent<NoParentNodePick<T>[K]> };
type NoParentNodePick<T extends NodeIdent> = Pick<T, Exclude<keyof T, "parent">>;
/**
* A view of an AST node that hides the `parent` property.
*/
export type NoParent<T> = T extends NodeIdent ? NoParentNode<T> : T extends unknown[] ? NoParentArray<T> : T; The (Sometimes splitting a recusive type into multiple types is sometimes a necessity due to TypeScript's recursion limitations.) I also want to add that I find it quite surprising this bundle auto-exports types. Other bundlers (like dts-bundle) do not do this. Is this behavior documented? |
Totally makes sense. Thanks for the clarification! I think we can add an option for that, something like
Are you about "mark all interfaces/types exported"? If so, then I'm not sure about "documented", but it's intended for sure. I mean, back in time "exporting all types in bundles" was one of the main reasons to create this tool. |
@RunDevelopment would you like to propose a PR with changes? |
Yes.
Then this should be documented for sure. You might want to tell people about your USP ;)
That's hard. Let me start by saying that How about
I'm sorry but no. |
I think we can add a note for the brand new option which describes this behavior enabled by default.
Agree. I think |
… directly from the root source file Fixes #153
Thank you @timocov! |
The new version 5.9 has been published with the fix. |
I just tested it out and it worked beautifully as expected. |
Bug report
This bundler exports private types. ("Private" as in "not exported". This has nothing to do with private fields.)
This is a problem because this means that you can no longer split one complex type into many simpler types.
Input code
This is a very simple example. In reality,
B
is reused across different exported types but kept private because it doesn't make sense on its own. Users of my library shouldn't be able to refer toB
, hence it is not exported.Expected output
Actual output
Additional context
CLI:
npx dts-bundle-generator -o my.d.ts src/foo.ts
The text was updated successfully, but these errors were encountered: