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

fix: plugin types compatibility issue with ctx.has #268

Merged
merged 7 commits into from
Aug 28, 2022

Conversation

Loskir
Copy link
Contributor

@Loskir Loskir commented Aug 25, 2022

Fixes #263

@EdJoPaTo EdJoPaTo self-requested a review August 25, 2022 18:17
@Loskir
Copy link
Contributor Author

Loskir commented Aug 26, 2022

This PR fixes the issue that resulted in typescript error being thrown when extending C extends Context C & {something: 1} (as discussed in Telegram)

However, it features additive implementation of NarrowMatch that was proven to work not as expected.

I think that this caveat is minor compared to the original issue. If we are unable to come up with a better alternative, this should be merged until we either find a better solution or split match into two properties in 2.0.

The original problem is very serious as it breaks numerous plugins

src/filter.ts Outdated
@@ -433,6 +433,10 @@ type Combine<U, K extends string> = U extends unknown
? U & Partial<Record<Exclude<K, keyof U>, undefined>>
: never;

export type FilterE<Q extends FilterQuery> = PerformQueryE<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great PQ, I'd just love to have a better suffix than E. What does it stand for, extension maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I agree :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me throw a bunch of random names at you:

  • FilterExtension
  • FilterCore
  • FilterAddition
  • FilterCasing
  • FilterShell
  • FilterCover
  • FilterSide
  • FilterWing
  • FilterAugmentation
  • FilterEnhancement
  • FilterAppendix
  • FilterAttachment
  • FilterAddendum

I think I prefer FilterCore. Which one do you like best?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilterCore, too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's rename then. Can you take care of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about exports and typedoc comments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think we need to export the *Core types. I see no reason to do this, as userland code would likely always want to use the full types. If there's ever demand for this, we can still export it in the future.

JSDoc comments are only necessary for exported stuff. Internal stuff may or may not have it, I'm mostly only doing this when things are hard to understand without comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Then it's done

@KnorpelSenf KnorpelSenf marked this pull request as ready for review August 28, 2022 12:44
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2022

Codecov Report

Merging #268 (b44354b) into main (bd13a27) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #268      +/-   ##
==========================================
+ Coverage   37.24%   37.27%   +0.02%     
==========================================
  Files          17       17              
  Lines        4331     4333       +2     
  Branches      157      157              
==========================================
+ Hits         1613     1615       +2     
  Misses       2716     2716              
  Partials        2        2              
Impacted Files Coverage Δ
src/filter.ts 90.27% <ø> (ø)
src/context.ts 23.22% <100.00%> (+0.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@KnorpelSenf
Copy link
Member

@EdJoPaTo should we wait for your review?

src/context.ts Outdated Show resolved Hide resolved
src/context.ts Outdated Show resolved Hide resolved
Co-authored-by: Kirill Loskutov <[email protected]>
Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

This fix will be shipped alongside Bot API 6.2 support.

@KnorpelSenf KnorpelSenf changed the title Fix issue with ctx.has fix: plugin types compatibility issue with ctx.has Aug 28, 2022
@KnorpelSenf
Copy link
Member

@Loskir please consider signing your commits.

I'll merge anyway now, but this would be nice to have for future contributions :)

@KnorpelSenf KnorpelSenf merged commit e9ae05b into grammyjs:main Aug 28, 2022
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

Successfully merging this pull request may close these issues.

bug: Type 'MyContext' does not satisfy the constraint 'Context'. Types of property 'has' are incompatible.
4 participants