Consider the following file:
/** myFile.ts **/
import something from 'something';
/** ... other imports here ... **/
export enum statuses = {
100 = "ok"
200 = "false"
};
export default class Model {
....
}
This is a dummy ORM model, which is used on the back-end. Now, what I would like to achieve, is to use part of it (specifically the enum from it) on the front-end also (which has a completely separate code base, with it's own node_modules and dependencies) but if I try to import the enum from this file, the something plugin dependencies is also being evaluated and imported, and my code fails, as that dependency is not part of the front-end codes dependencies.
Is there any way to perform an import on a javascript file, WITHOUT evaluating the dependencies and other part of the code? (with the known risk, that it may fail, if I try to import something that would need those dependencies)
For JavaScript, the answer is "no," and I'm 99% sure that's true for when TypeScript is handling the imports as well.
But it's easy to fix: Put the enum in its own module:
statuses.ts:
export enum statuses = {
100 = "ok"
200 = "false"
};
The other project can import from that, rather than from myFile.ts.
If you want, you make it so you don't have to update the code that does use myFile.ts to use that separate module, by re-exporting it in myFile.ts:
export { statuses } from "./path/to/statuses.js";
Or if you need to use statuses in myFile.ts (which you can't with the above):
import { statuses } from "./path/to/statuses.js";
export { statuses };
Either way, code that was doing import Modal, { statuses } from "./myFile.js" keeps working.