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

328
Views
Ampliar la interfaz definida en el archivo .d.ts no reconocido en la compilación

Así que estaba creando un bot de Discord con la biblioteca Discord.js y Typescript, pero no puedo entender por qué la clase que extendí funciona en el eslint, pero no en el compilador.

Aquí es donde creo el objeto del cliente.

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

Que tiene la clase Cliente, que no tiene estas propiedades:

 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);

Así que creé un archivo discord.d.ts en la raíz del proyecto en /types/common/discord.d.ts extendiendo la clase desde 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; } }

Pero solo funciona para el eslint, cuando intento compilar el bot me da el siguiente 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);

¿Puede alguien decirme lo que me estoy perdiendo aquí?

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!