gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

addEventHandler allows 1 parameter but removeEventHandler requires 2

Open kubk opened this issue 1 year ago • 1 comments

According to TypeScript it's possible to use addEventHandler with 1 parameter but it's not clear how to unsubscribe from it then:

this.telegramClient.addEventHandler(this.onUnknownEvent);
this.telegramClient.removeEventHandler(this.onUnknownEvent); // TS error - 2 arguments are expected

https://github.com/gram-js/gramjs/blob/2e8eff33c783dfd86a3fab98ab684637e33149cc/gramjs/client/TelegramClient.ts#L1111-L1123

kubk avatar Oct 11 '24 13:10 kubk

I see that addEventHandler eventually fallbacks to new Raw({}):

https://github.com/gram-js/gramjs/blob/2e8eff33c783dfd86a3fab98ab684637e33149cc/gramjs/client/updates.ts#L47

Can create a PR that either fixes addEventHandler typings (simpler but BC break) or marks removeEventHandler's second argument optional and loads the Raw class

kubk avatar Oct 11 '24 13:10 kubk