[phoenix] handle generics for the `on` function
Please fill in this template.
- [x] Use a meaningful title for the pull request. Include the name of the package modified.
- [x] Test the change in your own code. (Compile and run.)
- [x] Add or edit tests to reflect the change.
- [x] Follow the advice from the readme.
- [x] Avoid common mistakes.
- [x] Run
pnpm test <package to test>.
Select one of these and delete the others:
If changing an existing definition:
- [x] Provide a URL to documentation or source code which provides context for the suggested changes: <
> - [x] 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.
Why im making this change
This PR is here to enable a bit more flexability in the use of this packages type but putting in a generic for the on event callback. I have 2 motivations for making this change:
- To allow a bit cleaner code in our repos, always a win.
- To fix a potentially dangerous situtation, im not actually fixing it here as it would be a breaking change, (unless others feel this is a good idea), examples:
Currently, to inject types to this we do something like this locally
const channelHandler = channel.on('event', (res: { id: string }) => {
// some lovely code
})
which is fine, however because of the res?:any thats in the code and our overwritting of the type its far to easy to write something like
const channelHandler = channel.on('event', (res: { id: string }) => {
console.log(res.id)
})
which could cause an exception because res is optional.
The proposed change would result in a TS Error because we've been more specific in the typing, if this makes sense?
const channelHandler = channel.on<{ id: string }>('event', (res) => {
console.log(res.id) // TS error because res could be undefined
})
I've done this so that this would still be happy enough though the error would still get muted in this scenario, unless we release a breaking change and i'll remove the = any in the generic definition
const channelHandler = channel.on('event', (res: { id: string }) => {
// some lovely code
})
@benjaminkay93 Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.
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
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.
Inactive
This PR has been inactive for 7 days.
Diagnostic Information: What the bot saw about this PR
{
"type": "info",
"now": "-",
"pr_number": 74114,
"author": "benjaminkay93",
"headCommitOid": "d9f541ea54f1ec256f0c59bb1bd5d1413cc8f977",
"mergeBaseOid": "999d5c3c7b2b7efb4f525c136b8d44ab011ad100",
"lastPushDate": "2025-11-19T17:15:23.000Z",
"lastActivityDate": "2025-12-11T20:13:25.000Z",
"mergeOfferDate": "2025-12-11T20:14:06.000Z",
"hasMergeConflict": false,
"isFirstContribution": true,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "phoenix",
"kind": "edit",
"files": [
{
"path": "types/phoenix/index.d.ts",
"kind": "definition"
}
],
"owners": [
"mciastek",
"John-Goff",
"princemaple"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "sheetalkamat",
"date": "2025-12-11T20:13:25.000Z",
"isMaintainer": true
}
],
"mainBotCommentID": 3553831365,
"ciResult": "pass"
}
Hey @benjaminkay93,
: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!
🔔 @mciastek @John-Goff @princemaple — 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.
I don't think this is a good idea; this effectively hides an any by using a type variable that is only referenced once and therefore will always infer even if wrong.
so what i was trying to achieve was any being the default behaviour like it currently is, but when the type is explicitly known you can define what it is and overwrite the any behaviour
fwiw this is pretty much the same as defining a return type on a http request, sure technically you don't know for certain whats coming back, but if you control the API (like we do in this instance) you can define the type with reasonable certainty
@mciastek @John-Goff @princemaple any chance of a review from one of you here please? would be good to get a second thought on the matter
Re-ping @mciastek, @John-Goff, @princemaple:
This PR has been out for over a week, yet I haven't seen any reviews.
Could someone please give it some attention? Thanks!
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, @benjaminkay93.
(Ping @mciastek, @John-Goff, @princemaple.)
@benjaminkay93: Everything looks good here. I am ready to merge this PR (at d9f541e) 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! :heart:
(@mciastek, @John-Goff, @princemaple: you can do this too.)