I'm working on a discord bot in typescript and instead of passing client as an argument everywhere I would much rather access it only with message.client or base.client since everything extends the base class. The only issue is whenever doing message.client I have to inform the compiler that the client class is my own DiscordClient class:
const client = message.client as DiscordClient
const client = interaction.client as DiscordClient //Another example
I have extended global types before in an express app i used so i know its possible but i think im extending the wrong class.
Correct way from an epxress app:
declare global {
namespace Express {
interface User extends PrismaUser {}
}
}
I tried both capital letter and lowercase incase that was the issue but that did not fix it.
declare global {
namespace Base {
interface client extends DiscordClient {}
interface Client extends DiscordClient {}
}
}
This is the base class I am trying to extend from discord.js:
export abstract class Base {
public constructor(client: Client);
public readonly client: Client;
public toJSON(...props: Record<string, boolean | string>[]): unknown;
public valueOf(): string;
}
Edit: After looking into express library I found that I was extending an interface which is why it was working so I don't think the same would be possible for discord.js