-
Notifications
You must be signed in to change notification settings - Fork 106
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
Dynamically determine the type of ctx.match #81
Conversation
KnightNiwrem
commented
Nov 7, 2021
•
edited
Loading
edited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're calling it the verbose edition—is there a second PR that is less verbose, or what does this name imply?
Generally it looks like a good way to tackle this problem. However, I don't like at all how verbose things get because of this. I'm against merging unless we manage to cut it down.
trigger: MaybeNonEmptyArray<string>, | ||
...middleware: Array< | ||
Middleware<FilteredMatchContext<C, string, "callback_query:data">> | ||
> | ||
): Composer<FilteredMatchContext<C, string, "callback_query:data">>; | ||
callbackQuery( | ||
trigger: MaybeNonEmptyArray<RegExp>, | ||
...middleware: Array< | ||
Middleware< | ||
FilteredMatchContext<C, RegExpMatchArray, "callback_query:data"> | ||
> | ||
> | ||
): Composer< | ||
FilteredMatchContext<C, RegExpMatchArray, "callback_query:data"> | ||
>; | ||
callbackQuery( | ||
trigger: MustMixedNonEmptyArrayType<string, RegExp>, | ||
...middleware: Array< | ||
Middleware< | ||
FilteredMatchContext< | ||
C, | ||
string | RegExpMatchArray, | ||
"callback_query:data" | ||
> | ||
> | ||
> | ||
): Composer< | ||
FilteredMatchContext< | ||
C, | ||
string | RegExpMatchArray, | ||
"callback_query:data" | ||
> | ||
>; | ||
callbackQuery( | ||
trigger: MaybeNonEmptyArray<string | RegExp>, | ||
...middleware: Array< | ||
Middleware< | ||
FilteredMatchContext< | ||
C, | ||
string | RegExpMatchArray, | ||
"callback_query:data" | ||
> | ||
> | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to make this less verbose? I'm as uncomfortable as you probably are with half of the code in this file being type annotations of function overloads.
@@ -74,7 +74,7 @@ export class Context implements RenamedUpdate { | |||
* Used by some middleware to store information about how a certain string | |||
* or regular expression was matched. | |||
*/ | |||
public match?: string | RegExpMatchArray | null; | |||
public match?: string | RegExpMatchArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Agreed. There isn't a second PR that is less verbose.. or at least there wasn't. But I've managed to find a way to avoid code duplication for now, at the expense of longer type parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less lines, but now we're having wrong type annotations.
I need some more time to investigate this. Kinda want to see this merged, but still trying to make it more readable. Novice TS users need to be able to read the type annotations and get at least an idea of what this does. |
I appreciate your effort and I still want to see this problem solved, but the type annotations that are necessary to make this happen are getting out of hand. The annotations are not straightforward, and if we as developers of grammY think that, then it's already way to complicated for users, especially for the beginners among them. I do not support this change. In addition, #100 is going to complicate the implementation further. Do we then need four different kinds of context types, four different kinds of middleware types, and all of that for all affected methods? I am open to split Alternatively, we may look into disallowing mixing strings and regex in array on the type level. If anyone needs this, they could type-case explicitly to make it work, as the runtime code can continue supporting it. Either way, the change would need to be backed by the community. For example, if people mind having multiple almost identical methods more than minding the small inaccuracy in types, then we obviously will not touch the current code. Moreover, both suggestions are breaking changes, so they would have to wait until the next major release. Either way, I am going to close this PR for now. We may come back to it if anyone can think of a novel way to solve this, or if the tooling changes (who knows what TS does next). Thank you again for this attempt! |