Skip to content

[@types/node] Wrong type for ProcessEnv#51273

Closed
kylehalleman wants to merge 1 commit into
DefinitelyTyped:masterfrom
kylehalleman:master
Closed

[@types/node] Wrong type for ProcessEnv#51273
kylehalleman wants to merge 1 commit into
DefinitelyTyped:masterfrom
kylehalleman:master

Conversation

@kylehalleman
Copy link
Copy Markdown
Contributor

@kylehalleman kylehalleman commented Feb 16, 2021

The type for ProcessEnv is incorrect. It states it must be a string or undefined, but according to the Node documentation, the value can be a string, number, or boolean.

Assigning a property on process.env will implicitly convert the value to a string. This behavior is deprecated. Future versions of Node.js may throw an error when the value is not a string, number, or boolean.

While the deprecated behavior converts the value to a string, that does not mean you can’t assign a number or boolean.

It is clear from the documentation and examples in the docs that you can assign a string, number, or boolean.

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: https://nodejs.org/api/process.html#process_process_env
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Feb 16, 2021

@kylehalleman Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

Status

  • ✅ No merge conflicts
  • ❌ Continuous integration tests have failed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This PR has been inactive for 31 days — it is considered abandoned, and therefore closed!


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 51273,
  "author": "kylehalleman",
  "headCommitOid": "dc642ebfa3cf17fa9a0bd0a25cb2d88c26daf902",
  "lastPushDate": "2021-02-16T20:17:18.000Z",
  "lastActivityDate": "2021-02-17T21:52:40.000Z",
  "maintainerBlessed": false,
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/process.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/test/path.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v10/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v11/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v11/test/path.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v12/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v12/test/path.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v13/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v13/test/path.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v13/worker_threads.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/worker_threads.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "Microsoft",
        "DefinitelyTyped",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "brunoscheufler",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "KSXGitHub",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "galkin",
        "parambirs",
        "eps1lon",
        "SimonSchick",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "nguymin4",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "Ryan-Willpower",
        "peterblazejewicz",
        "addaleax",
        "JasonHK",
        "victorperin",
        "ZYSzys"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "changereq",
      "reviewer": "ExE-Boss",
      "date": "2021-02-16T23:06:14.000Z"
    }
  ],
  "ciResult": "fail",
  "ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/dc642ebfa3cf17fa9a0bd0a25cb2d88c26daf902/checks?check_suite_id=2054173674"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

node/v14.14

Comparison details for node/14.14 📊
master #51273 diff
Batch compilation
Memory usage (MiB) 135.7 130.8 -3.6%
Type count 22613 22615 0%
Assignability cache size 7587 7587 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 719.1 722.7 +0.5%
    Mean CV 9.1% 8.6%
    Worst duration (ms) 824.5 801.5 -2.8%
    Worst identifier wasi env
getQuickInfoAtPosition
    Mean duration (ms) 715.4 725.9 +1.5%
    Mean CV 9.9% 9.8%
    Worst duration (ms) 830.4 893.3 +7.6%
    Worst identifier start instance

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

node/v14.14

Comparison details for node/14.14 📊
master #51273 diff
Batch compilation
Memory usage (MiB) 123.4 128.1 +3.8%
Type count 22613 22615 0%
Assignability cache size 7587 7587 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 711.8 708.7 -0.4%
    Mean CV 10.4% 9.8%
    Worst duration (ms) 790.6 833.6 +5.4%
    Worst identifier wasi start
getQuickInfoAtPosition
    Mean duration (ms) 700.2 704.2 +0.6%
    Mean CV 9.3% 8.6%
    Worst duration (ms) 792.7 840.5 +6.0%
    Worst identifier instance start

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

node/v14.14

Comparison details for node/14.14 📊
master #51273 diff
Batch compilation
Memory usage (MiB) 130.5 131.5 +0.8%
Type count 22613 22615 0%
Assignability cache size 7587 7587 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 735.7 724.8 -1.5%
    Mean CV 9.5% 9.6%
    Worst duration (ms) 880.0 844.4 -4.0%
    Worst identifier start start
getQuickInfoAtPosition
    Mean duration (ms) 718.7 705.4 -1.9%
    Mean CV 8.6% 7.5%
    Worst duration (ms) 811.2 809.3 -0.2%
    Worst identifier start start

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

node/v14.14

Comparison details for node/14.14 📊
master #51273 diff
Batch compilation
Memory usage (MiB) 135.3 128.6 -5.0%
Type count 22613 22615 0%
Assignability cache size 7587 7587 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 716.4 705.4 -1.5%
    Mean CV 11.6% 9.2%
    Worst duration (ms) 802.3 814.3 +1.5%
    Worst identifier start wasi
getQuickInfoAtPosition
    Mean duration (ms) 706.0 701.6 -0.6%
    Mean CV 10.5% 8.3%
    Worst duration (ms) 865.8 827.6 -4.4%
    Worst identifier instance start

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

node/v14.14

Comparison details for node/14.14 📊
master #51273 diff
Batch compilation
Memory usage (MiB) 125.7 131.7 +4.8%
Type count 22613 22615 0%
Assignability cache size 7587 7587 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 715.1 716.6 +0.2%
    Mean CV 9.9% 11.7%
    Worst duration (ms) 824.6 823.5 -0.1%
    Worst identifier instance instance
getQuickInfoAtPosition
    Mean duration (ms) 711.6 699.7 -1.7%
    Mean CV 9.4% 9.0%
    Worst duration (ms) 796.7 879.9 +10.5%
    Worst identifier start start

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Feb 16, 2021
Copy link
Copy Markdown
Contributor

@ExE-Boss ExE-Boss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, there’s no way to do this without breaking a lot of things until microsoft/TypeScript#2521 (PR microsoft/TypeScript#42425) gets implemented.


That is also why DOM interface definitions don’t currently have the implicit string conversion either.

@typescript-bot typescript-bot added The CI failed When GH Actions fails Revision needed This PR needs code changes before it can be merged. labels Feb 16, 2021
@typescript-bot
Copy link
Copy Markdown
Contributor

@kylehalleman The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot
Copy link
Copy Markdown
Contributor

@kylehalleman One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@kylehalleman
Copy link
Copy Markdown
Contributor Author

@ExE-Boss I see that a lot of tests in other packages are failing. Taking a look at some of them, like color-support, I'm not sure why it fails if it references NodeJS.ProcessEnv in its declarations, and the tsconfig.json has typeRoots set to ../. I would think it would pick up the new definitions in this PR.

Regardless, I see the impact this is having. I think this would still be valuable even without microsoft/TypeScript#42425. Users who set an environment variable like process.env.PORT = 3000 a) expect TypeScript to not throw an error and b) expect to be able to later read that variable as a number and not string.

I might be in over my head here since this is obviously a core package to the ecosystem, so would appreciate your advice on moving forward.

@peterblazejewicz
Copy link
Copy Markdown
Member

Users who set an environment variable like process.env.PORT = 3000 a) expect TypeScript to not throw an error and b) expect to be able to later read that variable as a number and not string.

That's not current behaviour:

> process.env.PORT = 3000
3000
> process.env.PORT
'3000'

imo there is no clean cut option here

@kylehalleman
Copy link
Copy Markdown
Contributor Author

You're correct, my mistake. I swear I've been able to read the value as assigned before. But that might have been through something like webpack.

I suppose microsoft/TypeScript#42425 really is a blocker on this then.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Mar 13, 2021
@typescript-bot
Copy link
Copy Markdown
Contributor

@kylehalleman I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Mar 19th (in a week) if the issues aren't addressed.

@typescript-bot
Copy link
Copy Markdown
Contributor

@kylehalleman To keep things tidy, we have to close PRs that aren't mergeable and don't have activity in the last month. No worries, though — please open a new PR if you'd like to continue with this change. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned This PR had no activity for a long time, and is considered abandoned Critical package Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Revision needed This PR needs code changes before it can be merged. The CI failed When GH Actions fails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants