Skip to content
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

types: change Awaitable<void> to void #10017

Merged
merged 2 commits into from
Dec 17, 2023

Conversation

advaith1
Copy link
Contributor

@advaith1 advaith1 commented Dec 3, 2023

Please describe the changes this PR makes and why it should be merged:

Currently, event listeners require a function that returns Awaitable<void>. However, this prevents returning a function call that returns a value for early execution (e.g. return interaction.reply('error')). This PR changes => Awaitable<void> to => void, since void functions can return anything. This will remove the restriction and allow any function, bringing it in line with Node's standard EventEmitters, as well as previous discord.js behavior.

Status and versioning classification:

  • I know how to update typings and have done so, or typings don't need updating
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@advaith1 advaith1 requested a review from a team as a code owner December 3, 2023 01:47
Copy link

vercel bot commented Dec 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discord-js ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2023 1:52pm
discord-js-guide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2023 1:52pm

@Qjuh
Copy link
Contributor

Qjuh commented Dec 3, 2023

return void interaction.reply(…); would be the correct fix for your use-case. As returning something from an event listener while it will never reach any place that uses it should not be done imho.

@advaith1
Copy link
Contributor Author

advaith1 commented Dec 3, 2023

This is a normal pattern, and TypeScript explicitly supports it with the standard => void. This change makes discord.js consistent with Node's standard EventEmitter, async_event_emitter (used by djs/core), and previous versions of discord.js.

@Qjuh
Copy link
Contributor

Qjuh commented Dec 3, 2023

async_event_emitter returns Awaitable<void> too though.

@vladfrangu
Copy link
Member

async_event_emitter returns Awaitable<void> too though.

No it doesn't, it uses void

@Qjuh
Copy link
Contributor

Qjuh commented Dec 3, 2023

Oh, my bad, I was looking at the Listener type instead of the type used in on(…) assuming it was used there…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants