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

150
Visualizações
stream.write This expression is not callable

I am trying to a write a function that takes either writeable stream (createWriteStream) or process.stdout/.stderr but typescript keeps throwing this error. Error goes away when I do conditional type check.

import { createWriteStream, WriteStream } from 'fs'

const writehello = (stream: NodeJS.WriteStream & { fd: 1 } | WriteStream) => stream.write('hello\n') // error

writehello(process.stdout)
writehello(createWriteStream('/tmp/al.txt'))

Error message at line 3

error TS2349: This expression is not callable.
  Each member of the union type '{ (buffer: string | Uint8Array, cb?: ((err?: Error | undefined) => void) | undefined): boolean; (str: string | Uint8Array, encoding?: BufferEncoding | undefined, cb?: ((err?:
Error | undefined) => void) | undefined): boolean; } | { ...; }' has signatures, but none of those signatures are compatible with each other.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Both NodeJS.WriteStream and WriteStream overload the write() method, but they use different signatures, resulting in the error you are seeing.

Instead of defining the union type between these two types, you can define the type of the stream parameter using Writable, that is extended by both:

import { createWriteStream } from 'fs'
import { Writable } from 'stream'

const writehello = (stream: Writable) => stream.write('hello\n')

writehello(process.stdout)
writehello(createWriteStream('/tmp/al.txt'))
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