It appears that the contents you are looking for in src/Models/index.ts
should be as follows:
export * from "./User";
export * from "./Home";
Assuming your module resolution is configured correctly, you can then proceed to write:
import { User, UserOptions } from "my-module/Models";
By doing so, references to User
and UserOptions
will point to the class and type alias specified in src/Models/User.ts
, respectively. If both src/Models/User.ts
and src/Models/Home.ts
have symbols with identical names, the first export *
statement takes precedence.
Resolving Module Issues
If importing my-module/
suggests completions of src
and dist
, you may need to import the full relative path to the corresponding .js
and .d.ts
files (typically located within the dist
directory). To eliminate the presence of dist
in your import paths, several options are available, none of which are ideal:
- Avoid using separate
src
and dist
directories; organize all files starting from the project root.
- Employ a customizable module bundler or loader that allows customization for imports like
import "my-module/Models"
to directly access the dist
folder. If the current bundler/loader does not seamlessly integrate with TypeScript, utilize TypeScript's path mapping functionalities to align TypeScript's module resolution behavior with that of the bundler/loader.
- Manually redirect each import path to their respective files under the
dist
directory by creating either pairs of .js
and .d.ts
files that import the actual paths or a customized package.json
file containing fields such as main
and types
specifying the real paths.