I have a pretty large npm module written in TypeScript, which exposes a number of types, including several interfaces. Now these interfaces do not all make sense at the root level, which is why I would like to expose them in a way that they can be imported in a somewhat nested way.
Basically, I'm looking for a way to expose interface so that the user of the module can do:
import { Foo } from 'my-module';
import { Bar } from 'my-module/sub-part';
Is this possible in TypeScript, and if so, how? What does not work is this code in the root index.ts file:
export {
Foo,
{ Bar }
};
Please note that the .ts files are not located at the root directory of the module, and so the .js and .d.ts files aren't either.
How can I solve this?
PS: It's not about default vs named export here, since I want to have a solution for exporting interfaces in multiple nested levels.
package.jsonfile in thesub-partdirectory in your package's root and use themainandtypesentries in that file (they're gonna be the only ones you need to specify) to refer to the.d.tsand.jsfiles - which can be anywhere you like.declare module "my-module/sub-part" { export interface Bar { … } }?