#redeclaring a class in a library

5 messages · Page 1 of 1 (latest)

pseudo sable
#

hey! i'm making a discord bot template compatible with discord.js v14.

i've made a custom ```ts
import { Client } from 'discord.js'

class myClient extends Client
``` and since the Client of discord.js is a class extends Base (also a class of the same library), my custom client class is also based on that Base.

on the other hand, the Base class has a client property which returns the client. however, when i wanted to redeclare this class: ```ts
import { Client } from './classes' // my custom client class

declare module 'discord.js' {
abstract class Base {
public constructor(client: Client<true>);
public readonly client: Client<true>;
public toJSON(...props: Record<string, boolean | string>[]): unknown;
public valueOf(): string;
}
}
``` as it doesn't return my custom class and hardens completing my code, i encountered the error Duplicate identifier 'Base'. as my custom client is also based on this Base class which uses the custom client class as a value.

how can i prevent this collision?

#

-mention me plz when you reply-

echo holly
#

Hi @pseudo sable, i think the best way is redeclaring the interface typing :

import { Client } from 'discord.js'

class myClient extends Client {
   // Your new custom client properties
   isSomething(key: any) {
     return true;
   }
}

declare module 'discord.js' {
    export interface Client {
        // Your new custom client properties
        isSomething(key: any): true;
    }
}
pseudo sable
#

and thank you even more for teachin' me how declarations work ^^