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

225
Views
Is there a way to translate this TypeScript piece to JavaScript in node.js?

I need to use this in my .js file but I have no idea how to make it javascript. Here's the function:

async function readLines(filename: string, processLine: (line: string) => Promise<void>): Promise<void> {
    return new Promise((resolve, reject) => {
        lineReader.eachLine(filename, (line, last, callback) => {
            if (!callback) throw new Error('panic');
            processLine(line)
            .then(() => last ? resolve() : callback())
            .catch(reject);
        });
    });
}

Now here's how I call it:

await readLines(filename, async (line) => {
await delay(1000)
some_other_func(line);
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You just need to remove the parameter processLine type and the return value type.

async function readLines(filename, processLine) {
    return new Promise((resolve, reject) => {
        lineReader.eachLine(filename, (line, last, callback) => {
            if (!callback) throw new Error('panic');
            processLine(line)
            .then(() => last ? resolve() : callback())
            .catch(reject);
        });
    });
}
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!