DenisFrezzato / hyper-ts

Type safe middleware architecture for HTTP servers
https://denisfrezzato.github.io/hyper-ts/
MIT License
391 stars 18 forks source link

`pipeStream`: 'ReadableStream' is not assignable to 'Readable' #49

Closed DenisFrezzato closed 2 years ago

DenisFrezzato commented 3 years ago

🐛 Bug report

Current Behavior

Using pipeStream I get the following error.

[tsserver 2345] [E] Argument of type 'ReadableStream' is not assignable to parameter of type 'Readable'.
  Type 'ReadableStream' is missing the following properties from type 'Readable': readableEncoding, readableEnded, readableFlowing, readableHighWaterMark, and 7 more.

Expected behavior

No error is raised.

Reproducible example

import { pipe } from 'fp-ts/lib/function'
import * as H from 'hyper-ts'
import fetch from 'node-fetch'
import * as TE from 'fp-ts/TaskEither'

pipe(
  TE.tryCatch(
    () => fetch('...'),
    () => 'oops',
  ),
  H.fromTaskEither,
  H.ichain((res) =>
    pipe(
      H.status(H.Status.OK),
      H.ichain(() => H.closeHeaders()),
      H.ichain(() => H.pipeStream(res.body)),
                              //  --------
    ),
  ),
)

Suggested solution(s)

pipeStream should accept Readable | ReadableStream.

Your environment

Software Version(s)
fp-ts 2.10
hyper-ts 0.6.5
TypeScript 4.2

cc @MakhBeth

DenisFrezzato commented 3 years ago

This isn't actually a bug. The issue should be solved by using wrap.

      H.ichain(() => H.pipeStream((new Readable).wrap(res.body))),

@MakhBeth can you verify this?

EDIT: I've tested it, .wrap is the way to go, I'm closing this.

DenisFrezzato commented 2 years ago

I'm reopening this, NodeJS.ReadableStream is the proper type to use.