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

143
Views
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 answers
Answer question

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