Definitelytyped: @types/readable-stream throws error at run-time

Created on 18 May 2020  ยท  18Comments  ยท  Source: DefinitelyTyped/DefinitelyTyped

The following error was thrown from @types/readable-stream when starting a NestJS project.

Other observations:

  1. The @types/readable-stream was installed as a dependency for the mssql package.
    No error was thrown after the mssql package (and @types/readable-stream) was uninstalled
  2. No error was thrown from the previous version which uses string instead of BufferEncoding for encoding varables.

* Error Logs Start **
[18:59:15] Starting compilation in watch mode...

node_modules/@types/readable-stream/index.d.ts:13:15 - error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
The types of 'Stream.Readable.Writable' are incompatible between these types.
Type 'typeof _Readable.Writable' is not assignable to type 'typeof import("stream").Writable'.
Types of parameters 'options' and 'opts' are incompatible.
Type 'import("stream").WritableOptions' is not assignable to type '_Readable.WritableOptions'.
Type 'WritableOptions' is not assignable to type 'WritableStateOptions'.
Types of property 'defaultEncoding' are incompatible.
Type 'string' is not assignable to type 'BufferEncoding'.

13 declare class _Readable extends stream.Readable {
* Error Logs End **

Most helpful comment

I think there is double trouble here.

  1. In Node14 the stream transform method takes a BufferEncoding type instead of a vanilla string.
    Version 2.3.6 of this definition file assumes the user is on Node14. This should somehow be fixed to work on Node12 (current LTS) and Node14 (future LTS).

  2. The stream definition was recently updated in Node types. There are 2 new fields that impact Node12 and higher: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45175
    These fields have been carried over here in v2.3.7, but that version suffers from item 1 above.

For Node14, taking the latest definitions from both should work.

As a workaround for Node12, we can take the last version of both types before they started conflicting.
npm install --save-dev --save-exact @types/[email protected]
npm install --save-dev --save-exact @types/[email protected]

Hope we can get a fix for the first issue to make everybody happy!

All 18 comments

I ran into this at compilation time in v14.0.3. I downgraded to v12.12.7 and the problem went away.

This is likely due to an old/incompatible version of @types/readable-stream

I'm getting the same problem. Versions are:
Node 12.16.3
tsc 3.9.3
readable-stream 2.3.6 (which is used by mssql 6.2.0)
Any suggestions will be much appreciated!

Can you please provide a miminal repro? (package.json, package-lock.json, index.ts, tsconfig.json)?

See attached. These are part of a standard NestJS install. Thank you for investigating this - much appreciated.

On May 21, 2020, at 6:52 PM, Simon Schick <[email protected] notifications@github.com> wrote:

Can you please provide a miminal repro? (package.json, package-lock.json, index.ts, tsconfig.json)?

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44828#issuecomment-632385744, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHPHDWEZCYAGIBOWPTRWSTTRSWWCPANCNFSM4ND7RKBA.

I don't think attachments work when sent via email ๐Ÿ˜›

The basic repo (it was compressed using the standard Mac zip function).
studentapi001-old.zip

Apologies - I updated the issue instead.

On May 21, 2020, at 7:41 PM, Simon Schick notifications@github.com wrote:

I don't think attachments work when sent via email ๐Ÿ˜›

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44828#issuecomment-632399959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHPHDWER6BJ7JX5UN2PD5BTRSW33RANCNFSM4ND7RKBA.

Yea it seems readable-stream isn't quite compatible with with pre v14 node versions anymore, this is partially my bad.

Run npm i -D -E @types/[email protected] to downgrade the version, this will install a compatible version and make the version number static.

Shall do. Many thanks.

On May 21, 2020, at 8:01 PM, Simon Schick notifications@github.com wrote:

Yea it seems readable-stream isn't quite compatible with with pre v14 node versions anymore, this is partially my bad.

Run npm i -D -E @types/[email protected] to downgrade the version, this will install a compatible version and make the version number static.

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44828#issuecomment-632405508, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHPHDWBWKD4BHECIAGNBQELRSW6GHANCNFSM4ND7RKBA.

Having the same problem. Thanks for the workaround with the downgrade, that helps for now.

Having a similar problem here:

Node: v12.18.0
typescript: 3.9.5
readable-stream: 2.3.5
@types/readable-stream: 2.3.7

I tried downgrading readable-stream types, but it didn't help

../../node_modules/@types/readable-stream/index.d.ts:13:15 - error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
  The types of 'Stream.Readable.Writable' are incompatible between these types.
    Type 'typeof _Readable.Writable' is not assignable to type 'typeof import("stream").Writable'.
      Types of parameters 'options' and 'opts' are incompatible.
        Type 'import("stream").WritableOptions | undefined' is not assignable to type '_Readable.WritableOptions | undefined'.
          Type 'import("stream").WritableOptions' is not assignable to type '_Readable.WritableOptions'.
            Type 'WritableOptions' is not assignable to type 'WritableStateOptions'.
              Types of property 'defaultEncoding' are incompatible.
                Type 'string | undefined' is not assignable to type '"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined'.
                  Type 'string' is not assignable to type '"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined'.

13 declare class _Readable extends stream.Readable {

@SimonSchick, so once we upgrade to Node 14 we can use the most up to date version?

Should be, yes.

I tried with node 14.4.0 and I get the same error than with v12

yarn start                                                                                                                       โ–‘โ–’โ–“ โœ” | 14.4.0 Node 
yarn run v1.22.4
$ nest start
node_modules/@types/readable-stream/index.d.ts:13:15 - error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
  The types of 'Stream.Readable.Writable' are incompatible between these types.
    Type 'typeof _Readable.Writable' is not assignable to type 'typeof import("stream").Writable'.
      Types of parameters 'options' and 'opts' are incompatible.
        Type 'import("stream").WritableOptions' is not assignable to type '_Readable.WritableOptions'.
          Type 'WritableOptions' is not assignable to type 'WritableStateOptions'.
            Types of property 'defaultEncoding' are incompatible.
              Type 'string' is not assignable to type 'BufferEncoding'.

13 declare class _Readable extends stream.Readable {

@types/[email protected]

Well, even v2.3.5 don't work for me in node v12 and v14

What works for fixing the build for me is this change:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/readable-stream/index.d.ts#L13

-declare class _Readable extends stream.Readable {
+declare class _Readable {

It is dirty, but well, at least it builds. Looking forward for a fix really

I think there is double trouble here.

  1. In Node14 the stream transform method takes a BufferEncoding type instead of a vanilla string.
    Version 2.3.6 of this definition file assumes the user is on Node14. This should somehow be fixed to work on Node12 (current LTS) and Node14 (future LTS).

  2. The stream definition was recently updated in Node types. There are 2 new fields that impact Node12 and higher: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45175
    These fields have been carried over here in v2.3.7, but that version suffers from item 1 above.

For Node14, taking the latest definitions from both should work.

As a workaround for Node12, we can take the last version of both types before they started conflicting.
npm install --save-dev --save-exact @types/[email protected]
npm install --save-dev --save-exact @types/[email protected]

Hope we can get a fix for the first issue to make everybody happy!

Updating to node v12.18.1 @types/[email protected] fixed this issue for me.

Was this page helpful?
0 / 5 - 0 ratings