-
Notifications
You must be signed in to change notification settings - Fork 10
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
refactor: adapt for telegraf v4.0 and v3.38 #107
Conversation
this is not breaking compatibility with 3.38
telegraf typings arnt considered breaking in v3 and 3.38 works for sure
You can simply define it in the file: type MiddlewareFn<C extends Context> = (ctx: C, next: () => Promise<void>) => Promise<void> It's compatible with 3.38 and 4.x, and it should be forward-compatible with 5.x. |
Thank you for the suggestion @wojpawlik. Haven't thought about that. Normally I would be against redefining types as this might end up as a potential bug later on. On the other side: As |
I don't think you have a choice: making return type less specific is a breaking change. Anyway, why did you change const LocalSession = require('telegraf-session-local') to const LocalSession = require('../lib/session') // require('telegraf-session-local') in README? |
redefining something from a lib is bad but as the import changed it would be breaking otherwise
@@ -1,7 +1,8 @@ | |||
declare module 'telegraf-session-local' { | |||
import { AdapterSync, AdapterAsync, BaseAdapter } from 'lowdb' | |||
import { Context } from 'telegraf' | |||
import { MiddlewareFn } from 'telegraf/typings/composer' | |||
|
|||
type MiddlewareFn<C extends Context> = (ctx: C, next: () => Promise<void>) => Promise<void> |
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.
I meant
type MiddlewareFn<C extends Context> = (ctx: C, next: () => Promise<void>) => Promise<void> | |
type MiddlewareFn<C extends Context> = (ctx: C, next: () => Promise<void>) => Promise<unknown> |
Promise<void>
should work too, but void
's interactions are inconsistent.
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.
void is more precise than unknown?
Thank you guys for all of your work & conversation ❤️ PS> Happy New 2021 year! |
About the tests and Travis CI, why isnt travis listed in the checks? |
Figured out, that Travis-CI moved from .org to .com, so I migrated project to .com and now it should works fine as before. |
Please release this on npm. Until then, I cannot recommend this library in Telegraf 4's readme. |
@wojpawlik gonna release in 2 hours. How do you think, do we need to bump minor version to 2.1.0, or simply bump patch version to 2.0.1? |
Technically there is nothing new, just some fixes for the typings. So in that way, its a bugfix release. Practically its a feature (which is not breaking) so I would tend to a minor version bump. |
The good thing about this: it is not breaking compatibility with 3.38
closes #106
Explanation:
const {Telegraf} = require('telegraf')
already works in 3.38bot.launch()
already works in 3.38 (bot.startPolling()
was somewhat deprecated)The import Path of
MiddlewareFn
changed with the update to v4 butMiddleware
is exported from the main export in v3.38 and v4.0. This results in slightly less good typings but as you normally only usebot.use(sessionLocal)
you wont notice it.Keep in mind that telegraf v4 requires NodeJS 12. But this is not a requirement of this library on its own so no (breaking) change needed there.