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

339
Visualizações
Extend interface defined in .d.ts file not recognized on compile

So I was creating a Discord bot with the Discord.js library and Typescript, but I can't figure out why the class that I extended is working on the eslint, but not in the compiler.

This is where I create the client object.

const client = new Discord.Client({
  intents: [
    "GUILDS",
    "GUILD_MESSAGES",
    "GUILD_MEMBERS"
  ]
});

Which has the class Client, that don't have these properties:

client.commands = new Discord.Collection();
client.events = new Discord.Collection();

client.loadEvents = (botObject: typeof bot, reload: boolean) => require("./handlers/events")(botObject, reload);

client.loadEvents(bot, false);

So I created a discord.d.ts file at the root of the project on /types/common/discord.d.ts extending the class from Discord.js

import { Collection } from "discord.js";
import bot from "../../src/index";

declare module "discord.js" {
  export interface Client {
    commands: Collection<unknown, any>;
    events: Collection<unknown, any>;
    loadEvents: (botObject: typeof bot, reload: boolean) => any;
  }
}

But it only works for the eslint, when I try to compile the bot it gives me the following error:

TSError: ⨯ Unable to compile TypeScript:
src/index.ts:39:8 - error TS2339: Property 'commands' does not exist on type 'Client<boolean>'.

39 client.commands = new Discord.Collection();
          ~~~~~~~~
src/index.ts:40:8 - error TS2339: Property 'events' does not exist on type 'Client<boolean>'.

40 client.events = new Discord.Collection();
          ~~~~~~
src/index.ts:42:8 - error TS2339: Property 'loadEvents' does not exist on type 'Client<boolean>'.

42 client.loadEvents = (botObject: typeof bot, reload: boolean) => require("./handlers/events")(botObject, reload);
          ~~~~~~~~~~
src/index.ts:44:8 - error TS2339: Property 'loadEvents' does not exist on type 'Client<boolean>'.

44 client.loadEvents(bot, false);

Can anyone please tell me what I'm missing here.

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