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

Typescript support #32

Open
KnorpelSenf opened this issue Jul 22, 2019 · 7 comments
Open

Typescript support #32

KnorpelSenf opened this issue Jul 22, 2019 · 7 comments

Comments

@KnorpelSenf
Copy link

Title says it all.

Maybe node-telegram-bot-api's types can be used as a template. Then it is not needed to model the whole Telegram API again (just the methods specific to slimbot).

@edisonchee
Copy link
Owner

Sounds like a good idea. Seems like I'll have to publish a -typed version of Slimbot in order not to break existing projects.

I've also done some cursory research into maintaining this with Lerna, and it should be pretty straightforward.

@KnorpelSenf
Copy link
Author

Shouldn't it be sufficient to publish the types to DefinitelyTyped? I do not see how this would break existing projects. (Maybe that's because I am not too experienced with typescript yet.)

@edisonchee
Copy link
Owner

I'm beginning to look into TypeScript migration as it's becoming more necessary to manage method arguments safely, and will intend to publish an alpha for testing when it's ready.

@KnorpelSenf
Copy link
Author

KnorpelSenf commented Apr 20, 2020

Do you want to have the benefits of TypeScript available for your development of slimbot? Because if it's only about providing types to your users, consider writing a declaration file instead. This does not affect users of your library at all that do not want to use TS because the types can be published as a separate package that is linked to slimbot.
If you want to rewrite the bot with types (which sounds like more effort than it is), then a proper configuration allows an update without breaking changes, unless someone is making mistakes when calling your library. Not just weird but actually malfunctioning use causes type errors for them then.

@edisonchee
Copy link
Owner

edisonchee commented Apr 20, 2020

Yeah, for my own development, particularly when I'm doing manual testing for a method like createNewStickerSet where the png_sticker arg can either be a readableStream or just a string.

Your suggestion to write a declaration file is great though, it'll make for a safer upgrade for existing lib users. Thank you so much for your suggestion. I'll give this a go first before diving into migrating the entire project into TS.

@KnorpelSenf
Copy link
Author

@edisonchee I published TypeScript declaration files for the complete Telegram API in the npm package typegram. This could be of great help if you consider to pursue adding type annotations further.

This will probably even prevent you from having to migrate all the code to TS. Adding a few type signatures for your own methods and otherwise pulling in the existing types for the Telegram API should give you and your users 100 % coverage without much hassle.

@KnorpelSenf
Copy link
Author

KnorpelSenf commented Nov 21, 2021

There does not seem to be any progress on this issue. Moreover, there does not really seem to exist any other Node.js library that has good TypeScript support.

Hence, I decided to create a new library a few months ago that is written from the ground up in TypeScript. It is much smaller than slimbot and still a lot more powerful: https://github.com/grammyjs/grammY
Has good docs, too: https://grammy.dev

I do not need TypeScript support for slimbot anymore. However, I'll keep this issue open for reference.

Size comparison:

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

2 participants