Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addEventHandler allows 1 parameter but removeEventHandler requires 2 #732

Open
kubk opened this issue Oct 11, 2024 · 1 comment
Open

addEventHandler allows 1 parameter but removeEventHandler requires 2 #732

kubk opened this issue Oct 11, 2024 · 1 comment

Comments

@kubk
Copy link
Contributor

kubk commented Oct 11, 2024

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

addEventHandler(callback: { (event: any): void }, event?: EventBuilder) {
return updateMethods.addEventHandler(this, callback, event);
}
/**
* Inverse operation of addEventHandler().<br>
*
* @param callback - the callback function to be removed.
* @param event - the type of the event.
*/
removeEventHandler(callback: CallableFunction, event: EventBuilder) {
return updateMethods.removeEventHandler(this, callback, event);
}

@kubk
Copy link
Contributor Author

kubk commented Oct 11, 2024

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

event = new raw({}) as Raw;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant