-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[node] Add generics to 'EventEmitter' #68313
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
Conversation
|
@malthe Thank you for submitting this PR! This is a live comment which I will keep updated. 8 packages in this PR
Code ReviewsBecause 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
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"
} |
|
🔔 @Seikho @jonnysparkplugs @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 — please review this PR in the next few days. Be sure to explicitly select |
|
@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. |
|
Nice try |
d8dac2d to
109c2e9
Compare
109c2e9 to
155a6df
Compare
|
@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. |
155a6df to
3c7d3fc
Compare
People who would have been pingedLogvinovLeon 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 |
|
A note on the design presented here:
|
3c7d3fc to
b0efe22
Compare
acd8950 to
430b6d9
Compare
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, clever trick.
430b6d9 to
87bc265
Compare
|
@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? |
a2161fe to
c0da831
Compare
f4d45ea to
bc3a6b9
Compare
bc3a6b9 to
8838f07
Compare
|
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. |
|
@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. |
jakebailey
left a comment
There was a problem hiding this 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.
|
Ready to merge |
|
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). |
|
@ckohen no reason as far as I am aware. |
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).
Please fill in this template.
pnpm test <package to test>.Select one of these and delete the others:
If adding a new definition:
.d.tsfiles generated via--declarationdts-gen --dt, not by basing it on an existing project.tsconfig.jsonshould havenoImplicitAny,noImplicitThis,strictNullChecks, andstrictFunctionTypesset totrue.If changing an existing definition:
package.json.If removing a declaration:
notNeededPackages.json.