Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@types/readable-stream] Fix StringDecoder type usage in readable-stream #37869

Closed

Conversation

JonathanCallewaert
Copy link

StringDecoder is a value, but used as type. This gives an error ('StringDecoder' refers to a value, but is being used as a type here.) when trying to build. Add 'typeof' to fix this

StringDecoder is a value, but used as type. This gives an error ('StringDecoder' refers to a value, but is being used as a type here.) when trying to build. Add 'typeof' to fix this
@JonathanCallewaert JonathanCallewaert changed the title Fix StringDecoder type usage in readable-stream [@types/readable-stream] Fix StringDecoder type usage in readable-stream Aug 23, 2019
@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics.

Let’s review the numbers, shall we?

Comparison details 📊
master #37869 diff
Batch compilation
Memory usage (MiB) 67.9 68.1 +0.3%
Type count 9525 9525 0.0%
Assignability cache size 3360 3360 0.0%
Subtype cache size 1 1 0.0%
Identity cache size 7 7 0.0%
Language service
Samples taken 112 112 0.0%
Identifiers in tests 112 112 0.0%
getCompletionsAtPosition
    Mean duration (ms) 379.4 367.7 -3.1%
    Median duration (ms) 374.5 366.4 -2.2%
    Mean CV 13.2% 13.1% -0.6%
    Worst duration (ms) 473.8 425.3 -10.2%
    Worst identifier stream ANY
getQuickInfoAtPosition
    Mean duration (ms) 387.0 393.9 +1.8%
    Median duration (ms) 385.6 393.9 +2.2%
    Mean CV 13.7% 15.5% +13.6%
    Worst duration (ms) 476.0 456.2 -4.2%
    Worst identifier streamR RStream

It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place.


If you have any questions or comments about me, you can ping @andrewbranch. Have a nice day!

@typescript-bot typescript-bot added this to Waiting for Reviewers in Pull Request Status Board Aug 23, 2019
@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Aug 23, 2019
@typescript-bot
Copy link
Contributor

typescript-bot commented Aug 23, 2019

@JonathanCA97 Thank you for submitting this PR!

🔔 @TeamworkGuy2 - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@TeamworkGuy2
Copy link
Contributor

TeamworkGuy2 commented Aug 23, 2019

This change doesn't work for me locally, here's the auto-complete I get in VS2017 when I change the decoder field type to typeof StringDecoder | null:
image

Could you post some more details:

  • which version of typescript are you using to compile?
  • what configuration are you using (your tsconfig.json)?
  • what tool or IDE is generating this error and could you post the full error with stack trace from tsc compile command if possible?

@JonathanCallewaert
Copy link
Author

JonathanCallewaert commented Aug 24, 2019

Hi, thanks for your answer

  • I am using typescript version 3.5.3
  • My tsconfig.json looks like this:
  "compilerOptions": {
    "resolveJsonModule": true,
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "jsx": "react",
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "src/types/*"]
    },
    "lib": ["es2016", "es2017", "esnext.asynciterable"],
    "sourceMap": false
  },
  "include": ["src/**/*"]
}
  • I am using Visual Studio Code. This is the full error I get:
node_modules/@types/readable-stream/index.d.ts:137:18 - error TS2749: 'StringDecoder' refers to a value, but is being used as a type here.

137         decoder: StringDecoder | null;
                     ~~~~~~~~~~~~~


Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! orhechestrator@0.1.6 build: `rimraf dist; tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the orhechestratorl@0.1.6 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jonathan/.npm/_logs/2019-08-24T07_30_58_292Z-debug.log

The node version I use is 10.13.0

@JonathanCallewaert
Copy link
Author

If I follow the reference of StringDecoder, I come to this code:

declare module "string_decoder" {
    interface NodeStringDecoder {
        write(buffer: Buffer): string;
        end(buffer?: Buffer): string;
    }
    const StringDecoder: {
        new(encoding?: string): NodeStringDecoder;
    };
}

@TeamworkGuy2
Copy link
Contributor

TeamworkGuy2 commented Aug 24, 2019

I'm guessing you're using version ~10.x.x of @types/node in your package.json?

After investigating, I see the following issue between v10 and v12 of string_decoder.d.ts (latest).
To fix the issue, we're going to need to find a way to support both versions.
@types/node@~10.x.x https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v10/string_decoder.d.ts

declare module "string_decoder" {
    interface NodeStringDecoder {
        write(buffer: Buffer): string;
        end(buffer?: Buffer): string;
    }
    const StringDecoder: {
        new(encoding?: string): NodeStringDecoder;
    };
}

@types/node@~12.x.x https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/string_decoder.d.ts

declare module "string_decoder" {
    class StringDecoder {
        constructor(encoding?: string);
        write(buffer: Buffer): string;
        end(buffer?: Buffer): string;
    }
}

@JonathanCallewaert
Copy link
Author

Using @types/node V12 fixes it indeed, thanks!

@typescript-bot typescript-bot moved this from Waiting for Reviewers to Review in Pull Request Status Board Aug 28, 2019
@typescript-bot typescript-bot added the Unmerged The author did not merge the PR when it was ready. label Aug 28, 2019
@typescript-bot
Copy link
Contributor

After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Popular package This PR affects a popular package (as counted by NPM download counts). Unmerged The author did not merge the PR when it was ready.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants