Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'

I'm working on a bot for Discord using node/typescript. When I run the typescript compiler over my source code, I am getting this error:

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'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I've tried reinstalling @types/node since that seems to be the module where this is coming from, but that hasn't caused any changes. As far as I know, none of my source code is even making use of the readable-streams sub-module. In fact, removing it solves my problem - I just want to know what exactly happened. Here is my tsconfig.json in case I'm missing something there:

{

    "compilerOptions": {
        "target": "es6",
        "outDir": "built/",
        "moduleResolution": "Node"
    },
    "include": [
        "./bot/**/*"
    ]

}

I would appreciate any help on this. Hopefully I'm not the only person who's bumped into this situation. Thanks!

like image 727
Chai Snowman Avatar asked Mar 02 '23 10:03

Chai Snowman


1 Answers

I run into this issue lately. This seems to be a typing incompatibility between the last version of @types/readable-stream (2.3.6) and your version of node.

You can check in you yarn.lock / package-lock.json for the presence of this package in this version

It seems that @types/[email protected] is node >= 14-compatible while @types/[email protected] is node < 14-compatible

There is how I had it fixed in my environment node < 14:

yarn add -D --exact @types/[email protected]

Or with npm:

npm i -D -E @types/[email protected]

This overrides the @types/readable-stream package version and sets in explicitly to the 2.3.5 fixed version by adding "@types/readable-stream": "2.3.5" in your package.json devDependencies


I guess (but I didn't test it) that I you run into this same issue and your node version is >= 14, you might have to do perform the same operation with the 2.3.6 version of @types/readable-stream


Source: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44828

like image 52
Antoine Laffargue Avatar answered Mar 04 '23 23:03

Antoine Laffargue