Skip to content

Conversation

@malthe
Copy link
Contributor

@malthe malthe commented Jan 24, 2024

Please fill in this template.

Select one of these and delete the others:

If adding a new definition:

  • The package does not already provide its own types, or cannot have its .d.ts files generated via --declaration
  • If this is for an npm package, match the name. If not, do not conflict with the name of an npm package.
  • Create it with dts-gen --dt, not by basing it on an existing project.
  • Represents shape of module/library correctly
  • tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.

If changing an existing definition:

If removing a declaration:

  • If a package was never on Definitely Typed, you don't need to do anything. (If you wrote a package and provided types, you don't need to register it with us.)
  • Delete the package's directory.
  • Add it to notNeededPackages.json.

@malthe
Copy link
Contributor Author

malthe commented Jan 24, 2024

This fixes issue #25302 – see also discussion #55298.

@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 24, 2024

@malthe Thank you for submitting this PR!

This is a live comment which I will keep updated.

8 packages 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
  • ✅ A DT maintainer needs to approve changes which affect more than one package

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": 68313,
  "author": "malthe",
  "headCommitOid": "8838f077266af765677601d98af911c801996fa0",
  "mergeBaseOid": "2cf3fb47fcb10a2aaf5470ca8f12d6968b5e0726",
  "lastPushDate": "2024-01-24T17:55:47.000Z",
  "lastActivityDate": "2024-02-27T22:12:12.000Z",
  "mergeOfferDate": "2024-02-27T21:50:51.000Z",
  "mergeRequestDate": "2024-02-27T22:12:12.000Z",
  "mergeRequestUser": "malthe",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "newman",
      "kind": "edit",
      "files": [
        {
          "path": "types/newman/newman-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "LogvinovLeon"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "node-red",
      "kind": "edit",
      "files": [
        {
          "path": "types/node-red/node-red-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "andersea",
        "tbowmo",
        "bernardobelchior",
        "alexk111",
        "Shaquu"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/test/events_generic.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/ts4.8/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/test/events_generic.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/test/events_generic.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/ts4.8/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/ts4.8/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/ts4.8/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/ts4.8/test/events_generic.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/test/events_generic.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/events.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/ts4.8/node-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/test/events.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/test/events_generic.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "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"
    },
    {
      "name": "opossum",
      "kind": "edit",
      "files": [
        {
          "path": "types/opossum/opossum-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "quinnlangille",
        "merufm",
        "lance",
        "mastermatt",
        "tjenkinson"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Popular"
    },
    {
      "name": "rdf-store-fs",
      "kind": "edit",
      "files": [
        {
          "path": "types/rdf-store-fs/rdf-store-fs-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "tpluscode"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "sse",
      "kind": "edit",
      "files": [
        {
          "path": "types/sse/sse-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "yutak23"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "twitter",
      "kind": "edit",
      "files": [
        {
          "path": "types/twitter/twitter-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "BendingBender"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "xml-flow",
      "kind": "edit",
      "files": [
        {
          "path": "types/xml-flow/xml-flow-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Warerebel"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-02-27T21:50:05.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "yoursunny",
      "date": "2024-02-11T19:12:22.000Z",
      "abbrOid": "ab0ed35"
    },
    {
      "type": "stale",
      "reviewer": "mcollina",
      "date": "2024-01-26T18:08:21.000Z",
      "abbrOid": "430b6d9"
    }
  ],
  "mainBotCommentID": 1908647334,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 24, 2024

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Jan 24, 2024
@typescript-bot
Copy link
Contributor

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

@Semigradsky
Copy link
Contributor

Nice try

@typescript-bot typescript-bot added Edits multiple packages and removed The CI failed When GH Actions fails labels Jan 24, 2024
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Jan 25, 2024
@typescript-bot
Copy link
Contributor

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

@malthe malthe requested a review from borisyankov as a code owner January 25, 2024 10:27
@typescript-bot typescript-bot added Too Many Owners and removed The CI failed When GH Actions fails labels Jan 25, 2024
@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 25, 2024

⚠️ There are too many reviewers for this PR change (55). Merging can only be handled by a DT maintainer.

People who would have been pinged LogvinovLeon andersea tbowmo bernardobelchior alexk111 Shaquu Microsoft jkomyno alvis r3nya btoueg smac89 touffy DeividasBakanas eyqs Hannes-Magnusson-CK hoo29 kjin ajafff islishude mwiktorczyk mohsen1 n-e galkin parambirs eps1lon ThomasdenH WilcoBakker wwwy3y3 samuela kuehlein bhongy chyzwar trivikr yoursunny qwelias ExE-Boss peterblazejewicz addaleax victorperin ZYSzys NodeJS LinusU wafuwafu13 mcollina Semigradsky quinnlangille merufm lance mastermatt tjenkinson tpluscode yutak23 BendingBender Warerebel

@malthe malthe marked this pull request as draft January 25, 2024 10:38
@malthe
Copy link
Contributor Author

malthe commented Jan 25, 2024

A note on the design presented here:

  • There are some technical issues around Function vs (...args: any[]) => void. To allow existing tests to run unchanged, I have had to differentiate between these two and right now calling these types Listener1 and Listener2. Not ideal naming.

  • There are some test failures that are trivial to fix but annoying:

    6>   27:5  error  [email protected], 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4 expected type to be:
    6>   EventEmitter
    6> got:
    6>   EventEmitter<DefaultEventMap>  @definitelytyped/expect
    

    These cases can mostly be identified using:

    $ grep -R --exclude-dir=node_modules '// $ExpectType EventEmitter'

    See Generics with default and $ExpectType value microsoft/DefinitelyTyped-tools#919.

    Some packages such as @types/artillery do have an EventEmitter type that's tested using "$ExpectType" but defined as an interface:

    export interface EventEmitter extends events.EventEmitter {}

    In this case, the default generic type parameters do not appear in the listed type.

@malthe malthe changed the title [node] Add generic type to 'EventEmitter' [node] Add generics to 'EventEmitter' Jan 26, 2024
@malthe malthe force-pushed the generic-events branch 2 times, most recently from acd8950 to 430b6d9 Compare January 26, 2024 16:22
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, clever trick.

@malthe malthe marked this pull request as ready for review January 26, 2024 21:24
@typescript-bot
Copy link
Contributor

@mcollina Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot added Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. and removed Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. labels Feb 26, 2024
@jakebailey
Copy link
Member

jakebailey commented Feb 26, 2024

Thanks for updating the PR; are there any remaining concerns? This PR had a couple previous thumbs up, and I don't have any particular notes about this besides that it seems pretty complicated for just a mapping. (I think updating the actual mechanism for consuming T would still be possible post-merge.)

But, if it seems fine, we can try and revert if it breaks.

@malthe
Copy link
Contributor Author

malthe commented Feb 27, 2024

@jakebailey definitely agree that the complexity in the implementation is considerable (and somehow not particularly elegant), but I think the upshot is that the tests demonstrate that you can use this new generic typing in a simple, straight-forward way. I think we can iterate further on the implementation post-merge.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Okay, then I guess we'll give it a try.

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Feb 27, 2024
@malthe
Copy link
Contributor Author

malthe commented Feb 27, 2024

Ready to merge

@ckohen
Copy link
Contributor

ckohen commented Jun 24, 2024

Is there a reason generics were not added to the static methods? It is totally possible to detect the event map even in the static methods and provide the same safety there. I would be happy to do so but wanted to confirm there wasn't a reason it wasn't done in the first place (couldn't see one in reading through the PR).

@malthe
Copy link
Contributor Author

malthe commented Jun 25, 2024

@ckohen no reason as far as I am aware.

marmitar added a commit to marmitar/thelounge that referenced this pull request Nov 17, 2025
Fixed the type of `fs.watch`, which may pass to `null` for the callback
(DefinitelyTyped/DefinitelyTyped#65505).

Removed `WritableStream` type, since its events don't match `busboy`
anymore (DefinitelyTyped/DefinitelyTyped#68313).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants