Change TS type of Client

I've made some changes to the default Client by adding a config file and some collections. While this all works I can't figure out a way to change the type of the Client so it reflects my changes. Here's som of my code
export default class MCSSBot extends Client {
public config: Config
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public commandCollection: Collection<string, any> = new Collection();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public eventCollection: Collection<string, any> = new Collection();
}
export default class MCSSBot extends Client {
public config: Config
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public commandCollection: Collection<string, any> = new Collection();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public eventCollection: Collection<string, any> = new Collection();
}
I've tried adding a TS file as follows but it causes more issues that it solves
declare module "discord.js" {
export interface Client {
config: Config
commandCollection: Collection<string, any> = new Collection();
eventCollection: Collection<string, any> = new Collection();
}
}
declare module "discord.js" {
export interface Client {
config: Config
commandCollection: Collection<string, any> = new Collection();
eventCollection: Collection<string, any> = new Collection();
}
}
I understand why the issues exist but not how I can fix them
3 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs14mo ago
We highly recommend you extend the Client structure properly instead of just attaching custom properties like .commands to the regular discord.js Client instance. - Using typescript, you might want to consider casting or augmenting the module type
Poulette
Poulette14mo ago
For the any, I'm in the process of fixing those I'll have a look at those links, thanks I'm confused though. The code I sent above is a snippet, my custom client actually does a lot more in the background. The issue I have is, say when an interaction is triggered I get the interaction. If I want to do interaction.client.commandCollection it works but eslint is not happy. How would I go about fixing that since it doesn't look like casting can do it ? God I’m an idiot
Want results from more Discord servers?
Add your server