Given the directory structure:
lib |-index.ts |-helpers |-someHelper.ts |-otherHelper.ts |-formatSomething.ts |-getSomething.ts |-index.ts |-service |-someHook.ts |-otherFile.ts
lib/helpers/index.ts
would look like this:
// default exports import someHelper from "./someHelper"; import formatSomething from "./formatSomething"; // named exports export * from "./otherHelper"; export * from "./getSomething"; // default exports need to be re-exported export { someHelper, formatSomething, }
lib/index.ts
(main export of the library) would look like this:
export * from "./helpers"
Consumers should exclusively import from the main export of the library.
// do NOT: import { someFunction } from "lib/package/src/nested/directory" // do instead: // external packages: import { someFunction } from "@public-entrypoint" import { someFunction } from "@publicSymbol" // internal packages/libraries: import { someFunction } from "public-interface" import { someFunction } from "library-name"
When using external projects, only use public interfaces.