DefinitelyTyped icon indicating copy to clipboard operation
DefinitelyTyped copied to clipboard

fix(node): use `unknown` for `worker_threads.Worker` 'error' event argument `err`

Open jonasgeiler opened this issue 2 months ago β€’ 14 comments

A worker thread can throw anything via the throw keyword, which gets passed directly to 'error' event listeners. The event typings should not assume it is an Error object.

I am not sure if this is a breaking change, so I left the package.json version unmodified for now.


If changing an existing definition:

  • [X] Provide a URL to documentation or source code which provides context for the suggested changes:

    I have opened a PR for Node.js to reflect this in their documentation: nodejs/node#60300

    However, here is also a script proofing this should be changed:

    import { isMainThread, Worker } from "node:worker_threads";
    
    if (isMainThread) {
    	// Main thread.
    
    	const worker = new Worker(new URL(import.meta.url));
    
    	worker.on("error", (err /* Type is `Error`, but should be `unknown`. */) => {
    		console.log(typeof err); // Prints 'boolean'.
    	});
    } else {
    	// Worker thread.
    
    	throw false; // You can literally throw anything.
    }
    
  • [ ] If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the package.json.

jonasgeiler avatar Oct 17 '25 17:10 jonasgeiler

@jonasgeiler 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
  • πŸ• Only a DT maintainer can approve changes without tests

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 11 days.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 73919,
  "author": "jonasgeiler",
  "headCommitOid": "3b6a4ddb38621d9aef7c65219e75239409908861",
  "mergeBaseOid": "d5dcfe8db3c38034efa60d74df3e87800e43e507",
  "lastPushDate": "2025-10-17T17:26:05.000Z",
  "lastActivityDate": "2025-12-10T19:04:32.000Z",
  "hasMergeConflict": true,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/v20/worker_threads.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v22/worker_threads.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/worker_threads.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "r3nya",
        "btoueg",
        "touffy",
        "mohsen1",
        "galkin",
        "eps1lon",
        "WilcoBakker",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina",
        "Semigradsky",
        "Renegade334",
        "anonrig"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "changereq",
      "reviewer": "Renegade334",
      "date": "2025-11-11T22:11:19.000Z"
    }
  ],
  "mainBotCommentID": 3416453515,
  "ciResult": "pass"
}

typescript-bot avatar Oct 17 '25 17:10 typescript-bot

Hey @jonasgeiler,

:unamused: Your PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Please consider adding tests to cover the change you're making. Including tests allows this PR to be merged by yourself and the owners of this module.

This can potentially save days of time for you!

typescript-bot avatar Oct 17 '25 17:10 typescript-bot

πŸ”” @Microsoft @jkomyno @r3nya @btoueg @touffy @mohsen1 @galkin @eps1lon @WilcoBakker @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @NodeJS @LinusU @wafuwafu13 @mcollina @Semigradsky @Renegade334 @anonrig β€” 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.

typescript-bot avatar Oct 17 '25 17:10 typescript-bot

@Renegade334

  • Firstly, this exists like it is in DT because this is how the API is documented. In general, when it comes to behavioural inaccuracies, we ask that people also upstream fixes to the API documentation, otherwise we're just doing our own thing.

As I have mentioned above, I have already opened a PR to the Node.js Documentation here: nodejs/node#60300 If you want, I can convert this PR to a draft until that PR gets hopefully merged.

  • I think this should probably be merged as a major change, as this will be breaking for anyone consuming the error parameter in callbacks. This can't be expressed in a PR, but if you're happy, I'll add this commit to the v25 changeset.

Sounds good! That would work for me.

jonasgeiler avatar Oct 17 '25 17:10 jonasgeiler

As I have mentioned above, I have already opened a PR to the Node.js Documentation here: nodejs/node#60300

So sorry, I'm conditioned to not reading the boilerplate text! 🀦

Renegade334 avatar Oct 17 '25 17:10 Renegade334

Update: My PR to the Node.js documentation,Β nodejs/node#60300, has been merged!

jonasgeiler avatar Oct 20 '25 11:10 jonasgeiler

Re-ping @Microsoft, @jkomyno, @r3nya, @btoueg, @touffy, @mohsen1, @galkin, @eps1lon, @WilcoBakker, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @NodeJS, @LinusU, @wafuwafu13, @mcollina, @Semigradsky, @Renegade334, @anonrig:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

typescript-bot avatar Oct 28 '25 18:10 typescript-bot

It has been more than two weeks and this PR still has no reviews.

I'll bump it to the DT maintainer queue. Thank you for your patience, @jonasgeiler.

(Ping @Microsoft, @jkomyno, @r3nya, @btoueg, @touffy, @mohsen1, @galkin, @eps1lon, @WilcoBakker, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @NodeJS, @LinusU, @wafuwafu13, @mcollina, @Semigradsky, @Renegade334, @anonrig.)

typescript-bot avatar Nov 04 '25 18:11 typescript-bot

Merged into #73924, and will be visible in the v25 release. πŸ‘

I'm going to mark this PR as non-mergable just to avoid confusion.

Renegade334 avatar Nov 11 '25 22:11 Renegade334

@jonasgeiler 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!

typescript-bot avatar Nov 11 '25 22:11 typescript-bot

@jonasgeiler 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 Dec 11th (in a week) if the issues aren't addressed.

typescript-bot avatar Dec 05 '25 01:12 typescript-bot

Uhm I am not sure about the state of this PR...

@Renegade334 do I do anything?

jonasgeiler avatar Dec 05 '25 15:12 jonasgeiler

@jonasgeiler Unfortunately, this pull request currently has a merge conflict πŸ˜₯. Please update your PR branch to be up-to-date with respect to master. Have a nice day!

typescript-bot avatar Dec 10 '25 19:12 typescript-bot

Merged to the new v25 release as f482b2a4b4894734cf35d60697ec75b46b5c6b88. This PR can be closed.

Many thanks!

Renegade334 avatar Dec 10 '25 19:12 Renegade334