-
Notifications
You must be signed in to change notification settings - Fork 944
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
Migrate partially to TS #1108
Migrate partially to TS #1108
Conversation
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.
Formatting-only changes are not welcome.
Do you have any reason against using import type
?
I know that formatting-only changes are not welcome. We avoid them using Prettier. However, if someone commits code to the repo that does not follow the formatting conventions, I believe it is better to fix the formatting once and do it properly rather than permitting that people keep on submitting formattings that follow their own rules. That way, we can keep everyone in sync. I don't personally have something against import type declarations, I understand their purpose. I suggest following the recommendations from the TS team. I quote:
What they're basically saying is that this should only be used when necessary. |
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Is there anything you can say about the three major points I listed in the description? I'd be happy to see the remaining 37 compilation errors fixed |
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
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.
Sorry for being terse, there's a lot to cover!
By "formatting-only changes" meant the extra newlines in payload objects in telegraf.ts
, please revert those.
1.
src/core/replicators.ts
has a lot of errors because I don't really know what typemessage
has in all these methods. Who would invoke them anyway?
Replicators are used by Telegram::sendCopy
. You can try using Required<Pick<Message, ...>>
as param types.
3.
src/scenes/context.ts
has a few lines wherethis.current
is accessed—I really don't know how that is supposed to behave.
What's the problem?
telegraf/src/scenes/context.js
Lines 33 to 36 in 66b795a
get current () { | |
const sceneId = this.session.current || this.options.default | |
return (sceneId && this.scenes.has(sceneId)) ? this.scenes.get(sceneId) : null | |
} |
4. Also confer #1074 (comment) for a few more things that are planned. They could be done here, as well.
Please don't expand the scope of this PR, it's huge already! I'm considering requesting splitting it up.
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
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.
Just, updating these types will be quite a lot of work I believe, and I'd take the opportunity to rethink structure of replicators. I don't like that copyMethods
is on the same level as text
for example... I'd rather export { copyMethods, replicators }
.
Similarly, I'd rather not touch markup
and perhaps session
at all than doing a poor job that needs immediate fixing.
For reference: https://github.com/telegraf/telegraf/blob/60635c3/src/markup.ts, https://github.com/telegraf/telegraf/blob/60635c3/src/core/replicators.ts, https://github.com/telegraf/telegraf/blob/60635c3/src/session.ts.
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Co-authored-by: Wojciech Pawlik <woj.pawlik@gmail.com>
Well the problem is that these types are also directly exposed to library consumers. I agree on all the other stuff you said but I still don't quite see how we could switch to generated For this PR we most likely have to re-enable |
If this change breaks something, this behavior should've been tested
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.
One does not simply fix that script.
What use-case requires the library to be fully typed?
I'm nitpicking at this point. Great work, I'll merge it after 24 hours, in case me, you or @dotcypress spots something wrong. Looking forward to reviewing your subsequent PRs :)
I see … I had a look at the repo and didn't feel like doing that either.
You might have heard of I know that technically this would all work without TS in the first place, but if it actually ends up being as generic as I'm contemplating, then I don't want to think about all the bugs I introduce when I don't have full type safety. The main reason behind having
Thanks! |
Can I somehow use these typings in my project? |
@KnorpelSenf thank you man. btw, is there any wizardscene typings you know of? EDIT: I've done I lack a lot of knowledge in regards of relates to typescript, but is it right that I can't use ctx.wizard when adding middlewares to the wizard scene? If anybody has that issue too, let me know. I checked the wizard scene ts file, and it looked alright. I mean there's an implemented middleware object that's doing something to use the wizard context but for some reason it's not working. is that a bug or am I missing out on something? |
Even though I migrated the module, I'm not an expert on wizards, so I cannot really help you here. Feel free to open an issue and remember to include an SSCCE if possible. People won't necessarily read an old PR that's already been merged some time ago. |
@KnorpelSenf I think I worked it out by changing some types . |
Description
Tighten TS config, eliminate most JS files, add missing types for most files. Also, the project did not follow its own prettier config, I reformatted the code in these places and removed
prettier-ignore
comment where I touched the code anyway.Extra::caption
ovewrties itself #1076session.ts
#1113The only thing currently missing is updating the types provided by
telegram-types
so that they are reflecting the API in version 4.9.src/markup.ts
would have a few errors. I fixed #1076 (comment), but what about #1076 (comment)? This calls for breaking changes. Some other dependant methods would have errors as a side-effect, they need to be fixed, too. This PR currently only suppresses all of the compilation errors by casting toany
where necessary, butmarkup.ts
should be rewritten in the future.Type of change
This PR mainly changes typings.
How Has This Been Tested?
npm run typecheck
Otherwise, thorough testing is still an open task for this PR. It needs to be verified that no breaking changes other than the intended ones are introduced. Especially testing the lib by using it in other projects is important, so most likely will some types need to be changed again later on.
Checklist:
I have added tests that prove my fix is effective or that my feature works(does not apply)