8000 feat: add AbortSignal.timeout(number) by zone117x · Pull Request #60628 · DefinitelyTyped/DefinitelyTyped · GitHub
[go: up one dir, main page]

Skip to content

feat: add AbortSignal.timeout(number) #60628

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

Closed

Conversation

zone117x
Copy link
Contributor
@zone117x zone117x commented Jun 1, 2022

Add AbortSignal.timeout(number) definition to @types/node, available since Nodejs v17.3.0, v16.14.0.

See https://nodejs.org/api/globals.html#static-method-abortsignaltimeoutdelay for more details.

Select one of these and delete the others:

If changing an existing definition:

@typescript-bot
Copy link
Contributor
typescript-bot commented Jun 1, 2022

@zone117x 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 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": 60628,
  "author": "zone117x",
  "headCommitOid": "1ee7f133f45f1375cd370c5b63a7b61dab3a0180",
  "mergeBaseOid": "e8b369c1b9d01c667aa871bc714dd23561a21cea",
  "lastPushDate": "2022-06-02T12:59:12.000Z",
  "lastActivityDate": "2022-06-10T01:47:19.000Z",
  "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/v14/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/globals.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/test/globals.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": "mcollina",
      "date": "2022-06-05T11:49:11.000Z",
      "isMaintainer": false
    },
    {
      "type": "stale",
      "reviewer": "eps1lon",
      "date": "2022-06-01T23:21:14.000Z",
      "abbrOid": "c77989d"
    }
  ],
  "mainBotCommentID": 1144190626,
  "ciResult": "fail",
  "ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/1ee7f133f45f1375cd370c5b63a7b61dab3a0180/checks?check_suite_id=6764929039"
}

@typescript-bot
Copy link
Contributor

@zone117x zone117x force-pushed the fix/node-abortsignal-timeout branch from ee4dc2b to c77989d Compare June 1, 2022 22:30
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Jun 1, 2022
@typescript-bot
Copy link
Contributor

@zone117x 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 which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Jun 2, 2022
@typescript-bot
Copy link
Contributor

@zone117x 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 which are failing do not end up on the list of PRs for the DT maintainers to review.

@zone117x
Copy link
Contributor Author
zone117x commented Jun 2, 2022
8000

@peterblazejewicz I'm struggling with getting this to work. It looks like the problem is that AbortSignal is defined in typescript/lib/lib.dom.d.ts as well as in @types/node, so if I add a property I'm getting the error:

Subsequent variable declarations must have the same type.  Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; }', but here has type 'AbortSignalConstructor'.

lib.dom.d.ts(1923, 13): 'AbortSignal' was also declared here.

image

Is it possible to make this change without also changing typescript/lib/lib.dom.d.ts? Is there a way to decouple the two types? I'm not even sure why lib.dom is being included in this context.

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Jun 2, 2022
@typescript-bot
Copy link
Contributor

@zone117x 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 which are failing do not end up on the list of PRs for the DT maintainers to review.

@peterblazejewicz
Copy link
Member

I assume this is because some setups use, say:

/// <reference types="node" />

(a global reference)
and within tsconfig:

lib: [ "dom" ]

this results in both being used to resolve the same symbol.
Old problem without any clear solution as of yet. Simon, which done a ton of work for @types/node recently, created this TS issue:
microsoft/TypeScript#43972

@yoursunny
Copy link
Contributor

How about making @types/web a peer dependency of @types/node, then importing types from that library?
This ensures consistency between typings, for projects that target both Node and browsers.

Copy link
Contributor
@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Jun 5, 2022
@zone117x
Copy link
Contributor Author
zone117x commented Jun 6, 2022

@peterblazejewicz

Old problem without any clear solution as of yet. Simon, which done a ton of work for @types/node recently, created this TS issue:
microsoft/TypeScript#43972

Ah, looks like the issue keeps getting pushed as well. I've been looking at how this is handled in similar scenarios, for example with the URL & URLSearchParams globals:

global {
interface URLSearchParams extends _URLSearchParams {}
interface URL extends _URL {}
interface Global {
URL: typeof _URL;
URLSearchParams: typeof _URLSearchParams;
}
/**
* `URL` class is a global reference for `require('url').URL`
* https://nodejs.org/api/url.html#the-w 8000 hatwg-url-api
* @since v10.0.0
*/
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: any, URL: infer URL }
? URL
: typeof _URL;
/**
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`
* https://nodejs.org/api/url.html#class-urlsearchparams
* @since v10.0.0
*/
var URLSearchParams:
// For compatibility with "dom" and "webworker" URLSearchParams declarations
typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams }
? URLSearchParams
: typeof _URLSearchParams;
}

Does an approach like this make sense for AbortController & AbortSignal? One potential issue is that since the DOM definition doesn't include AbortSignal.timeout(number), this workaround would make it so that the projects that reference the dom lib will use the dom AbortSignal definition rather than the @types/node one (if I am understanding this workaround).

@yoursunny

How about making @types/web a peer dependency of @types/node, then importing types from that library?
This ensures consistency between typings, for projects that target both Node and browsers.

Interesting, is there precedent for doing something like this, especially in this package?

@zone117x
Copy link
Contributor Author
zone117x commented Jun 6, 2022

@antongolub it looks like you have experience with this situation (like in #58619) -- any suggestions here?

@yoursunny
Copy link
Contributor

How about making @types/web a peer dependency of @types/node, then importing types from that library?
This ensures consistency between typings, for projects that target both Node and browsers.

Interesting, is there precedent for doing something like this, especially in this package?

No precedent, but this could be a solution.

A drawback is that the typing would not be able to capture the difference between web standards and Node implementation.
If a certain method or property is available in browsers but unavailable in Node, the typing would still indicate that it is available.
But then, this situation already exists when developer needs to do runtime feature testing to detect browser support for methods and properties that are not universally available.
They just have to do the same sort of runtime feature testing in Node instead of expecting the typing to accurately match the running Node version.

@peterblazejewicz
Copy link
Member

@zone117x I'm not using Node on daily basis (.NET stack here), I do not have opinion on this one, as this was always problematic and I do not have a great experience on seeing in wider context a subtle change and it's possible ramification(s). The issue you've linked #58019 was the one approved by MS team member, e.g. see this comment on what I mean:
#58619 (comment)

@zone117x
Copy link
Contributor Author
zone117x commented Jun 9, 2022

@rbuckton do you have any recommendations for a workaround here?

@rbuckton
Copy link
Collaborator

Unfortunately, I think the only solution is to update lib.dom in TypeScript to also have AbortSignalConstructor. Starting in TS 4.5 it's now possible to override lib.dom via a package dependency, but I don't think that would help in this case.

@typescript-bot
Copy link
Contributor

@zone117x 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 Jul 10th (in a week) if the issues aren't addressed.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Jul 3, 2022
@typescript-bot
Copy link
Contributor

@zone117x 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 Owner Approved A listed owner of this package signed off on the pull request. The CI failed When GH Actions fails
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0