Skip to content

[node] Update typings to v22.4.0#70262

Merged
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
Semigradsky:node-22.4.0
Aug 16, 2024
Merged

[node] Update typings to v22.4.0#70262
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
Semigradsky:node-22.4.0

Conversation

@Semigradsky
Copy link
Copy Markdown
Contributor

https://github.com/nodejs/node/releases/tag/v22.4.0

  • deps,lib,src: add experimental web storage
  • doc: doc-only deprecate OpenSSL engine-based APIs
  • util: support --no- for argument with boolean type for parseArgs

Fix #70056

https://github.com/nodejs/node/releases/tag/v22.4.0

- deps,lib,src: add experimental web storage
- doc: doc-only deprecate OpenSSL engine-based APIs
- util: support --no- for argument with boolean type for parseArgs
@Semigradsky Semigradsky marked this pull request as ready for review August 14, 2024 08:41
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Aug 14, 2024

@Semigradsky Thank you for submitting this PR!

This is a live comment that 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.

You can test the changes of this PR in the Playground.

Status

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

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 70262,
  "author": "Semigradsky",
  "headCommitOid": "1b6295c63babc5496d3f06584b756f900570f518",
  "mergeBaseOid": "eaedfc05e7edfd29de7be492d527d8bcfd691a88",
  "lastPushDate": "2024-08-10T11:54:53.000Z",
  "lastActivityDate": "2024-08-16T18:06:48.000Z",
  "mergeOfferDate": "2024-08-16T16:50:14.000Z",
  "mergeRequestDate": "2024-08-16T18:06:48.000Z",
  "mergeRequestUser": "Semigradsky",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/node/test/util.ts",
          "kind": "test"
        },
        {
          "path": "types/node/tls.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/util.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "galkin",
        "parambirs",
        "eps1lon",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina",
        "Semigradsky"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-08-16T16:35:41.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 2288184805,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. labels Aug 14, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Aug 14, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

Comment thread types/node/globals.d.ts
Comment on lines +165 to +181
/**
* A browser-compatible implementation of [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
* Data is stored unencrypted in the file specified by the `--localstorage-file` CLI flag.
* Any modification of this data outside of the Web Storage API is not supported.
* Enable this API with the `--experimental-webstorage` CLI flag.
* @since v22.4.0
*/
var localStorage: Storage;

/**
* A browser-compatible implementation of [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).
* Data is stored in memory, with a storage quota of 10 MB.
* Any modification of this data outside of the Web Storage API is not supported.
* Enable this API with the `--experimental-webstorage` CLI flag.
* @since v22.4.0
*/
var sessionStorage: Storage;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should these use the DOM types if available?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Storage is interface, it extends existing DOM type if available.

@Semigradsky
Copy link
Copy Markdown
Contributor Author

@jakebailey could you please take a look?

@jakebailey jakebailey closed this Aug 16, 2024
@jakebailey jakebailey reopened this Aug 16, 2024
@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Aug 16, 2024
@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Aug 16, 2024
@Semigradsky
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit d261c18 into DefinitelyTyped:master Aug 16, 2024
Comment thread types/node/globals.d.ts
* Enable this API with the `--experimental-webstorage` CLI flag.
* @since v22.4.0
*/
var localStorage: Storage;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Semigradsky what are you thoughts about this suggested change?

Since these globals are only available at runtime when the --experimental-webstorage is passed, I'd say it's confusing to provide them without needing runtime checks.

Suggested change
var localStorage: Storage;
var localStorage: Storage | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The convention within @types/node (mostly) is not to type features that live behind flags as possibly undefined.

Not only does this force type checking/assertions on projects that know their own build environment, but for global variables, it's just incorrect: it's not the case that the variable is potentially undefined, it's that it potentially doesn't exist, and those are not equivalent.

declare var localStorage: Storage | undefined;

// TypeScript tells me I should check that this isn't undefined...
if (localStorage) {
  localStorage.clear();
}

The TypeScript compiler is perfectly happy here, which makes it a rather jarring experience when you run this and encounter Uncaught ReferenceError: localStorage is not defined.

Copy link
Copy Markdown
Contributor

@kraenhansen kraenhansen Jan 8, 2025

Choose a reason for hiding this comment

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

Ophf 🤔 You're right. That case is not covered. I wondered if using never would be better, but it doesn't seem to be the case.

At the very least, this could have an experimental tag? Not that I'd expect great IDE support for highlighting that 😔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One thing to note is that you still need to end up in a position where loading the Node types and the DOM types together doesn't fall over; DT should be testing that already, and I would suspect that adding | undefined would probably cause errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another alternative to keep things sane around types for experimental features would be to separate these experimental types into a separate file, such that users can opt into the feature via a simple top-level import:

import type "node/experimental-webstorage";

Is that something which has been discussed already?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's a good idea to introduce imports which would crash at runtime; there's no way to enforce that an import is only used as a type import.

IMO this seems like a lot of work for not too much benefit; I'll note that the DOM types have some cases like this already for features that are only enabled in secure contexts, and those aren't even experimental.

Copy link
Copy Markdown
Contributor

@kraenhansen kraenhansen Jan 9, 2025

Choose a reason for hiding this comment

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

I don't think it's a good idea to introduce imports which would crash at runtime;

I agree and that's the point of my initial comment. In its current form the localStorage is declared while most likely not even defined, resulting in the Uncaught ReferenceError: localStorage is not defined for the average user, as @Renegade334 mentioned above. Putting this in a separate file, users would at least have to opt-into getting these experimental types declared on the global namespace.

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

Labels

Author is Owner The author of this PR is a listed owner of the package. Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants