-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conflict between discord.js + @nodes/types after upgrading #10358
Comments
A quick inspection leads to this being reproducible only with TypeScript 5.5.2. |
Another quick inspection shows that this is not related to the However, |
I also encountered this issue when type-checking my personal project that uses After further investigation, I found that TS 5.5 throws errors for module augmentation, which is what you are doing to the I can use I don't see a bug report in the TypeScript repo yet, so I've been doing more researching and thinking about submitting one. |
I found microsoft/TypeScript#58907 earlier, but I was not sure if it was related. |
Yeah it's happening outside of discord.js, I can't seem to public on<Event extends keyof ClientEvents>(event: Event, listener: (...args: ClientEvents[Event]) => void): this; |
This sounds more like a TS 5.5.2 issue, which I'd recommend opening an issue on their side (if one wasn't opened already) |
Classes are explicitly unmergeable; this only worked previously due to a specific bug related to merging aliased symbols, which was patched in microsoft/TypeScript#58326. The error here is unfortunately intended behaviour. Methods on the class prototype are overloadable via interface merging, but as things stand, static methods on the constructor aren't. |
So is there a better solution to prevent the errors? |
On our side, we could use interface merging, but that has its own can of worms. We probably want to take a look at adding these extensions only on the client(s) |
There is an alternative approach, I suppose. export class Client<Ready extends boolean = boolean> extends BaseClient {
// ...
// Override static EventEmitter methods, with added type checks for Client events.
public static once<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
eventEmitter: Emitter,
eventName: Emitter extends Client ? Event : string | symbol,
): Promise<Emitter extends Client ? ClientEvents[Event] : any[]>;
public static on<Emitter extends EventEmitter, Events extends keyof ClientEvents>(
eventEmitter: Emitter,
eventName: Emitter extends Client ? Events : string | symbol,
): AsyncIterableIterator<Emitter extends Client ? ClientEvents[Events] : any[]>;
} This would provide type-safe versions of those methods, without needing to interfere with (vlad: I think this is probably the sort of thing you were alluding to in your comment?) |
See #7986 for why this augmentation was added in the first place - |
as a temporary workaround:
prevents EventEmitter already defined errors in the project |
For future reference: A bug report was submitted in the TypeScript repo, and the maintainers confirmed that this is intended behavior - class augmentations cannot be merged. |
Any update on this issue? I was hoping to have a fix soon so I could update my typescript. |
They made a pr which solves the issue, still waiting for merge, but you can install the commit manually by doing: #10360 to install the pr correctly, first: uninstall discord.js
second: add the following to your package.json (to still use it as "discord.js"
third: then install it by doing
sometimes you have to call Alternative: Manually inserting the correct typesyou can also do the following instead of installing the fix of pr, while beeing on the latest ts version
this will work fine for types |
I‘d still suggest not doing too many manual workarounds like that. Instead wait for a proper fix, which will probably be in When that happens the linked PR would be obsolete too. |
I don't believe using a resolution like that would work since this is a monorepo... |
Another workaround is to use https://yarnpkg.com/package?name=eventemitter2 which is compatible with node's EventEmitter like code |
Which package is this bug report for?
discord.js
Issue description
Hi there, approximately two hours ago @nodes/types upgraded their package. I use GitHub Actions to build and test my discord bot, and I didn't realize I was out-of-date until I got conflicting errors that were very confusing.
As far as I can tell, I believe that @ nodes/types did some important changes and now discord.js is conflicting with those changes, and this is an issue with discord.js but I'm not sure. I'm not overly a huge expert on these types of things.
You can replicate this issue by installing the latest @nodes/types and the latest development build of discord.js. Upon attempting to build your project, you will be greeted with this error:
Code sample
Versions
typescript - 5.5.2
discord-js - latest development build
@types/node - 20.14.7
Node - Latest v20
Issue priority
High (immediate attention needed)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
Guilds, GuildMembers, GuildMessages, MessageContent
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: