Currently, I am in the process of developing a library package using Typescript that will eventually be published to the npm
registry for use by various projects.
To ensure that type definitions are also exported along with the code, I have followed the guidelines outlined in the publishing documentation, where the --declaration
option is set to true for tsc
resulting in the creation of *.d.ts
files.
However, I have noticed that these exports are spread across different folders and users of my package need to import them as shown below:
import { FooType } from 'my-test-pacakge/dist/src/foo/types';
import { BarInterface } from 'my-test-package/dist/src/foo/bar';
I find this approach a bit messy and I am considering creating a custom declaration file to better organize them. Is it acceptable to structure the imports this way, or should I implement a more streamlined solution for consumers?
Some suggestions online propose exporting the API through a general index.ts file, which seems like a valid option. However, I am uncertain if importing directly from the dist
folder is frowned upon in terms of best practices. What do you think?