Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda