discord.js icon indicating copy to clipboard operation
discord.js copied to clipboard

revert: add types to `EventEmitter` static methods

Open KhafraDev opened this issue 3 years ago • 4 comments

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

KhafraDev avatar Sep 20 '22 01:09 KhafraDev

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)

vercel[bot] avatar Sep 20 '22 01:09 vercel[bot]

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%> (ø)

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

codecov[bot] avatar Sep 20 '22 02:09 codecov[bot]

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.

vladfrangu avatar Sep 20 '22 11:09 vladfrangu

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')) {
	// ...
}

KhafraDev avatar Sep 20 '22 17:09 KhafraDev

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

almeidx avatar Oct 06 '22 09:10 almeidx