Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda