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

103
Visualizações
Construct an array with ES6-style imports

I am trying to convert some Node javascript code to typescript, which means converting require()s to imports.

Here is the original javascript:

const stuff = [
    require("./elsewhere/part1"),
    require("./elsewhere/part2"),
    // ...
];

Node-style require()s return an object, but ES6-style imports don't:

import part1 from "./elsewhere/part1"
// ...

const stuff = [ part1, /* ... */];

What can I do to retain the clean look of the original javascript in typescript?

Thank you for your time.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think your only option would be to use dynamic imports instead, since they return a Promise, but it has the drawback of making everything asynchronous, even if it isn't:

const stuff = await Promise.all([
    import("./elsewhere/part1"),
    import("./elsewhere/part2"),
    // ...
]);

I'd prefer your original version of static imports.

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