Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Importing something without evaluating the dependencies

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)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda