Declaration files in a monorepo not working as expected

145 views Asked by At

I have a monorepo of npm that contains two projects in the packages folder, project "a" and project "b" in the project a I use node:events and I edit EventEmitter types in the index.d.ts. In the project b I do the same but I declare diffrent types for node:events module and EventEmitter class, the problem occurs when the types of project a are in the test of project b and I don't know why.

There is the code for project "a":

declare module "node:events" {

   

    class EventEmitter {

        on: (<K extends keyof ChatBotEvents>(event: K, listener: (...args: ChatBotEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof ChatBot>, listener: (...args: any[]) => void) => this);
        emit: (<K extends keyof ChatBotEvents>(event: K, ...args: ChatBotEvents[K]) => boolean) &
            (<S extends string | symbol>(event: Exclude<S, keyof ChatBotEvents>, ...args: any[]) => boolean);

        off: (<K extends keyof ChatBotEvents>(event: K, listener: (...args: ChatBotEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof ChatBotEvents>, listener: (...args: any[]) => void) => this);


        once: (<K extends keyof ChatBotEvents>(event: K, listener: (...args: ChatBotEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof ChatBotEvents>, listener: (...args: any[]) => void) => this);

        removeAllListeners: (<K extends keyof ChatBotEvents>(event?: K) => this) &
            (<S extends string | symbol>(event?: Exclude<S, keyof ChatBotEvents>) => this);

    }

}

export interface ChatBotEvents {
        PRIVMSG: [message: PrivMSG]
        CLEARCHAT: [message: ClearChat]
        CLEARMSG: [message: ClearMessage]
        JOIN: [channel: JoinedChannel]
        LEAVE: [channel: JoinedChannel]
        ready: []
}

And there is the code of project b:


declare module "node:events" {


    class EventEmitter {

        on: (<K extends keyof PubSubEvents>(event: K, listener: (...args: PubSubEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof PubSubEvents>, listener: (...args: any[]) => void) => this);
        emit: (<K extends keyof PubSubEvents>(event: K, ...args: PubSubEvents[K]) => boolean) &
            (<S extends string | symbol>(event: Exclude<S, keyof PubSubEvents>, ...args: any[]) => boolean);

        off: (<K extends keyof PubSubEvents>(event: K, listener: (...args: PubSubEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof PubSubEvents>, listener: (...args: any[]) => void) => this);


        once: (<K extends keyof PubSubEvents>(event: K, listener: (...args: PubSubEvents[K]) => void) => this) &
            (<S extends string | symbol>(event: Exclude<S, keyof PubSubEvents>, listener: (...args: any[]) => void) => this);

        removeAllListeners: (<K extends keyof PubSubEvents>(event?: K) => this) &
            (<S extends string | symbol>(event?: Exclude<S, keyof PubSubEvents>) => this);

    }

}

export interface PubSubEvents{
    
        ready: []
}

I'm pretty sure that I have all the declaration right.

Thanks in advance.

I expect that in the test of the project b I have the types of EventEmitter of the declaration file of that project, as I import the class from project b.

0

There are 0 answers