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

revert: add types to EventEmitter static methods #8644

Closed
wants to merge 1 commit into from

Conversation

KhafraDev
Copy link
Contributor

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

Fixes #8634
Reverts #7986

Status and versioning classification:

  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Sep 20, 2022

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

1 Ignored Deployment
Name Status Preview Updated
discord-js ⬜️ Ignored (Inspect) Sep 20, 2022 at 1:59AM (UTC)

@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Merging #8644 (cc90b40) into main (c446a84) will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #8644      +/-   ##
==========================================
+ Coverage   86.66%   86.68%   +0.01%     
==========================================
  Files          86       87       +1     
  Lines        8771     8784      +13     
  Branches     1105     1110       +5     
==========================================
+ Hits         7601     7614      +13     
  Misses       1128     1128              
  Partials       42       42              
Flag Coverage Δ
builders 100.00% <ø> (ø)
collection 100.00% <ø> (ø)
proxy 74.10% <ø> (ø)
rest 91.99% <ø> (ø)
utilities 100.00% <ø> (?)
voice 63.86% <ø> (ø)
ws 60.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/actions/src/formatTag/formatTag.ts 100.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vladfrangu
Copy link
Member

I don't see why we should revert this 😕
Yes, if you have discord.js installed and in use somewhere, the types for on/once will get that intellisense. I'd argue thats expected behavior, even if it leaks into other files that might not use discord.js 🤷

Nevertheless I'm fine with the revert if others are too (but I feel like it's a downgrade in experience for those that do use this)

CC @discordjs/the-big-4 for other thoughts.

@KhafraDev
Copy link
Contributor Author

KhafraDev commented Sep 20, 2022

No strong opinion (the autocomplete is just wrong & annoying) but this is almost 100% better off left to a utility function or to the users since it has side effects.

import events from 'node:events'
import type { Client, ClientEvents } from 'discord.js'

export const once = <K extends keyof ClientEvents>(
	eventEmitter: Client,
	eventName: K
): Promise<ClientEvents[K]> => events.once(eventEmitter, eventName)

export const on = <K extends keyof ClientEvents>(
	eventEmitter: Client,
	eventName: K
): AsyncIterableIterator<ClientEvents[K]> => events.on(eventEmitter, eventName)

and then used the same

declare const client: Client

const [member] = await once(client, 'guildMemberAdd')

for await (const [channel] of on(client, 'channelCreate')) {
	// ...
}

@almeidx
Copy link
Member

almeidx commented Oct 6, 2022

Alternative PR which fixes the issue instead of reverting: #8681

@KhafraDev KhafraDev closed this Oct 7, 2022
@KhafraDev KhafraDev deleted the events-once branch October 7, 2022 03:35
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.

types: overriding events.once type causes bad intellisense autocompletion elsewhere
6 participants