Commit cbb34eb
fix(check): make node:stream/web types alias the globals (#34606)
## Summary
Fixes the long-standing type error where passing a `new
ReadableStream()` to `Readable.fromWeb()` (and similar `node:stream`
helpers) fails type checking:
```ts
import { Readable } from "node:stream";
Readable.fromWeb(new ReadableStream());
// ~~~~~~~~~~~~~~~~~~~~~
// TS2345: Argument of type 'ReadableStream<any>' is not assignable
// to parameter of type 'import("stream/web").ReadableStream<any>'.
```
The bundled `@types/node` declarations for `node:stream/web` defined
`ReadableStream`/`WritableStream`/`TransformStream` as separate
structural interfaces. Because Deno's global `ReadableStream`
(`lib.deno_web.d.ts`) and the node module's `ReadableStream`
cross-reference each other through methods like `pipeThrough`,
TypeScript could not prove them structurally compatible, so the two
looked like distinct types to the checker.
At runtime `node:stream/web` exposes the same classes Deno uses for its
globals, so this PR replaces the redeclarations with type/value aliases
pointing straight at the global types. The aliases match reality and let
platform values flow through `Readable.fromWeb`, `Writable.fromWeb`,
`Duplex.fromWeb`, etc. without explicit conversions.
Fixes #19620.
Closes denoland/divybot#356
## Test plan
- [x] New spec test `tests/specs/check/node_stream_from_web` exercises
both `node:stream/web` and global stream values through
`fromWeb`/`toWeb`.
- [x] Reproduction from the issue now type checks cleanly:
```
$ deno check repro.ts
Check repro.ts
```
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>1 parent 385a4a9 commit cbb34eb
4 files changed
Lines changed: 177 additions & 380 deletions
File tree
- cli/tsc/dts/node/stream
- tests/specs/check/node_stream_from_web
- tools
0 commit comments