Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!