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

[node] Add type side of global Blob, along with tests #62654

Merged

Conversation

thw0rted
Copy link
Contributor

Please fill in this template.


Fixes one missing piece from #59905

@typescript-bot
Copy link
Contributor

typescript-bot commented Oct 11, 2022

@thw0rted 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.

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": 62654,
  "author": "thw0rted",
  "headCommitOid": "81101a592ff1c2ac77eab5f73f8eb9bb6ecd440f",
  "mergeBaseOid": "f36edcdf706a824610a44c2c542449869d143a64",
  "lastPushDate": "2022-10-11T09:22:02.000Z",
  "lastActivityDate": "2022-10-12T19:00:10.000Z",
  "mergeOfferDate": "2022-10-12T18:46:04.000Z",
  "mergeRequestDate": "2022-10-12T19:00:10.000Z",
  "mergeRequestUser": "thw0rted",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/buffer.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/stream.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/test/buffer.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/buffer.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/ts4.8/stream.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/ts4.8/test/buffer.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Microsoft",
        "DefinitelyTyped",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "galkin",
        "parambirs",
        "eps1lon",
        "SimonSchick",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "peterblazejewicz",
      "date": "2022-10-12T18:45:19.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 1274392145,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Oct 11, 2022
@thw0rted
Copy link
Contributor Author

cc @peterblazejewicz , who reviewed the linked PR and 4.8 backport.

@doteric
Copy link

doteric commented Oct 11, 2022

Hello @thw0rted

I'm having an issue with the 16.11.65 version of @types/node and I'm wondering if this would fix it (probably it would).

node_modules/@types/node/ts4.8/stream.d.ts(842,39): error TS2304: Cannot find name 'Blob'.

Adding dom to the tsconfig.json might actually bypass this error, but dom shouldn't really be added in a pure node.js app I guess... Looks like some unexpected breaking change was introduced.

The change was fine for v18 I guess, but a breaking change for v16 and anything under I guess.

@thw0rted
Copy link
Contributor Author

Yes @doteric, this PR is designed to fix the error you mention. Until it is merged, you could use an older version of @types/node, from before #59905 was merged.

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Oct 11, 2022
@meyfa
Copy link
Contributor

meyfa commented Oct 11, 2022

@thw0rted Possibly I'm missing something obvious... why would this fix problems with @types/node@16, when changes are only made to the files at the top-level directory, that get released as @types/node@18?

@thw0rted
Copy link
Contributor Author

thw0rted commented Oct 11, 2022

Thanks @meyfa, I didn't notice that. Sorry, I don't actually have a super firm grasp of how the simultaneous-versioning thing works here on DT. I'll update the linked PR to address that as well, then.

ETA: or maybe not? See my next comment, not sure if/how this one is my fault.

@thw0rted
Copy link
Contributor Author

@doteric, did your code work with an older 16.x version of @types/node previously? The line you reference has been the same since #57678 -- it references a global Blob that comes from lib: ['dom'], so I would think that means it should never have worked without the consuming project also including lib-dom. If you included it successfully without lib-dom, I'd like to figure out how that happened.

@meyfa
Copy link
Contributor

meyfa commented Oct 11, 2022

@thw0rted The same error reported by @doteric also happened for me in an automated upgrade from 16.11.63 to 16.11.65: meyfa/eslint-config#41. 16.11.63 was previously working. The bot that made the PR provides a link to see the diff of the NPM package: https://app.renovatebot.com/package-diff?name=@types%2fnode&from=16.11.63&to=16.11.65.

The removal of the Blob interface from stream/consumers seems like the only relevant change there.
I think .d.ts files automatically export everything, so the comment above the declaration ("This interface is not, and should not be, exported.") may have been incorrect, and the definition of Blob was exposed to the global scope that way.

During development and CI, the now missing Blob was not noticed because the v16 tsconfig.json still depends on DOM, but unless users also depend on DOM, then the error will manifest in their projects (as you mentioned).

@meyfa
Copy link
Contributor

meyfa commented Oct 11, 2022

Should we maybe perform all the same changes from #59905 to the v14 and v16 directories as well, so that Blob becomes available again, and so that v14 and v16 become independent of DOM, just like version 18?

@thw0rted
Copy link
Contributor Author

Thanks for refreshing my memory, it's been months since I initially did this work and I had forgotten about the incorrect comment, which actually sparked this whole process in the first place.

Backporting the changes to v16 (at least) makes sense, I think. Maybe v14 as well, though it has no stream/consumers and thus no erroneous global Blob. I have to imagine the user base for v14 is getting pretty small by now, it's only on LTS until this coming April.

I don't have a lot of spare cycles right now, and probably won't at least through the end of the year or so. If you have time to do the port, awesome, and if you don't I'll try to fit it in eventually but can't make any predictions about a timeline.

@meyfa
Copy link
Contributor

meyfa commented Oct 12, 2022

I'll see what I can do!

@doteric
Copy link

doteric commented Oct 12, 2022

@doteric, did your code work with an older 16.x version of @types/node previously? The line you reference has been the same since #57678 -- it references a global Blob that comes from lib: ['dom'], so I would think that means it should never have worked without the consuming project also including lib-dom. If you included it successfully without lib-dom, I'd like to figure out how that happened.

@thw0rted yes, it worked perfectly fine previously. Yesterday I also set a temporary resolution to the version 16.11.62 and it works fine.

@meyfa
Copy link
Contributor

meyfa commented Oct 12, 2022

Quick update, I noticed Blob was added to globals only in v18. So depending on it would be a mistake, as it isn't available at run-time. Actually, the "mistake" of removing it brought us closer to reality. Still we need to fix other types in v16 depending on it.

meyfa added a commit to meyfa/DefinitelyTyped that referenced this pull request Oct 12, 2022
Blob is only available on the global object starting in Node 18. Still,
the `stream` definitions used the global Blob. This means that
`@types/node` 16.x is currently broken. This patch adds the correct
import to resolve this problem. For more info please refer to DefinitelyTyped#62654.

Long-term, IMHO we should remove `"lib": ["dom"]` from the v16 TSConfig
like it was already done for v18, but I'd much rather get this fix out
quickly and worry about that later.
@meyfa
Copy link
Contributor

meyfa commented Oct 12, 2022

I opened #62672 which should be the minimum change needed to fix v16. After that is merged we can try getting rid of DOM entirely for v16.

Copy link
Member

@peterblazejewicz peterblazejewicz left a comment

Choose a reason for hiding this comment

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

LGTM!
@thw0rted thanks!

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Oct 12, 2022
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Author to Merge in New Pull Request Status Board Oct 12, 2022
@typescript-bot
Copy link
Contributor

@thw0rted: Everything looks good here. I am ready to merge this PR (at 81101a5) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@microsoft, @DefinitelyTyped, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @SimonSchick, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13, @mcollina: you can do this too.)

@thw0rted
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Oct 12, 2022
@typescript-bot typescript-bot merged commit 3123ee3 into DefinitelyTyped:master Oct 12, 2022
typescript-bot pushed a commit that referenced this pull request Oct 15, 2022
…able in v16 by @meyfa

Blob is only available on the global object starting in Node 18. Still,
the `stream` definitions used the global Blob. This means that
`@types/node` 16.x is currently broken. This patch adds the correct
import to resolve this problem. For more info please refer to #62654.

Long-term, IMHO we should remove `"lib": ["dom"]` from the v16 TSConfig
like it was already done for v18, but I'd much rather get this fix out
quickly and worry about that later.
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

5 participants