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

202
Visualizações
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 Respostas
Responde à pergunta

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 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