gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.27k stars 178 forks source link

addEventHandler allows 1 parameter but removeEventHandler requires 2 #732

Open kubk opened 2 hours ago

kubk commented 2 hours ago

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 commented 2 hours ago

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