Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Globally extending a class/type from another package

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda