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

197
Views
Cannot use 'callback' with fs, Typescript

Yo, I have this peice of code in my API and it gives me an error I don't understand.

Code :

server.get('/deleteall', async (request, reply) => {
  var json = JSON.stringify(deleteall);
  fs.writeFile('todos.json', json, 'utf8', callback);
  return 'File overwritten.'
})

Error :

Argument of type '(arg0: string, json: string, arg2: string, callback: any) => void' is not assignable to parameter of type 'NoParamCallback'.

The error happens on build, I don't understand it at all, keep in mind, this is my first TS experience.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The callback argument for fs.write() is defined like this:

export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;

Whatever you have defined as callback does not match that type definition. It should be something like:

function callback(err) {
  console.log(err);
}

Or specified inline:

fs.writeFile('todos.json', json, 'utf8', (err) => console.log(err));

As a more general comment: I suggest you migrate to the promises API to escape callback hell.

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!