How can I export all types in the generated index.d.ts file?
By default, in the generated .d.ts file, only the type of the entry file is exported; but when other projects use this npm package, they need to use more types, and those types are not exported.
Version number: rollup@4 typescript@5 rollup-plugin-dts@6
Same question
I ran into the same problem and did not find a satisfying solution: https://github.com/utopia-os/utopia-ui/pull/122#issuecomment-2665845557
Please provide a minimal reproduction 🙏🏻.
Maybe you don't export thoes types. This plugin works like tree-shaking in ES modules, removing types that are not exported.
Please provide a minimal reproduction 🙏🏻.
Maybe you don't export thoes types. This plugin works like tree-shaking in ES modules, removing types that are not exported.
The types are part of the resulting .d.ts, but they are not exported there. This does not allow to import them from a third party.
This happens with nested types e.g.:
export interface Mother {
element: Child
}
The Child is not explicitly exported, but is inherently needed for the Interface.
It would be good if we would have an option to export such implicit types without the need to explicitly export them.
A simple in-practice example is an Interface you expose like this:
interface SomeType {}
export function do(input: SomeType){
...
return
}
The resulting .d.ts looks like this:
interface SomeType {}
declare function do(input: SomeType): void;
export { do };
Now I want to call the do() function from an external library. It cannot excess SomeType since its not explicitly exported.
The type is present in the .d.ts, but i cannot import it.
Current workaround: Export the type and all subtypes explicitly
export interface SomeType {}
export function do(input: SomeType){
...
return
}
The resulting .d.ts looks like this:
interface SomeType {}
declare function do(input: SomeType): void;
export { type SomeType, do };
I believe that's the expected and standard behavior: users can only import what you explicitly export, correct? 🤔
It's like defining two functions:
function private() {
...
}
function public() {
private();
...
}
export { public };
Users can only access the explicitly exported public function. The types work the same way, it shouldn't change the intent of your source code.
I agree - but this is very tedious to maintain.
It would be good to have the option to export all defined type used in public interfaces.
Implicitly adding "export" may cause export duplicate name conflicts.
type Child = string
export interface Public {
child: Child
}
type PublicChild = number
export { PublicChild as Child }
↓
// Look, there are now two "Child" exports.
export type Child = string
export interface Public {
child: Child
}
type PublicChild = number
export { PublicChild as Child }
I see. So there is no chance to get an option to try to export all types, since it has structural weaknesses?
We need to export all types and subtypes explicitly in consequence.
Its fine with me - maybe this behaviour and the resulting limits could be documented to prevent further questions.
Thank you for your time to investigate!