Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

322
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!