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

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

Open KhafraDev opened this issue 3 years ago • 4 comments

Which package is this bug report for?

discord.js

Issue description

image

Code sample

import { once } from 'events'
import { createServer } from 'http'
import { request } from 'undici'

const server = createServer(async (req, res) => {
	req.setEncoding('utf-8')
	for await (const chunk of req) console.log(chunk)
	
	res.end()
}).listen(0)

await once(server, '') // <-----

// @ts-ignore
await request(`http://localhost:${server.address().port}`, {
	body: new Uint8Array([65, 66, 67, 68])
})

server.close()

Package version

14.3.0

Node.js version

18.9.0

Operating system

n/a

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Not applicable (subpackage bug)

I have tested this issue on a development release

No response

KhafraDev avatar Sep 18 '22 15:09 KhafraDev

https://github.com/discordjs/discord.js/pull/7986#discussion_r886333659

imranbarbhuiya avatar Sep 18 '22 16:09 imranbarbhuiya

It has no effect on the event emitter types for anything else

@suneettipirneni this seems like a bug as it shouldn't affect other, non-djs things?


or is it because both node's http server and discord.js Client extend EventEmitter?

KhafraDev avatar Sep 18 '22 16:09 KhafraDev

or is it because both node's http server and discord.js Client extend EventEmitter?

yeah because the type in djs is adding an overload to the node:events so you'll see all these event names + any other overload if exists + any string

imranbarbhuiya avatar Sep 18 '22 16:09 imranbarbhuiya

yeah because the type in djs is adding an overload to the node:events so you'll see all these event names + any other overload if exists + any string

I'm not entirely sure why this is the case since I expect overloads to match based on parameter type. Nonetheless I suppose this would need to be reverted.

suneettipirneni avatar Sep 18 '22 17:09 suneettipirneni