slimbot icon indicating copy to clipboard operation
slimbot copied to clipboard

Typescript support

Open KnorpelSenf opened this issue 6 years ago • 7 comments

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).

KnorpelSenf avatar Jul 22 '19 20:07 KnorpelSenf

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.

edisonchee avatar Jul 27 '19 06:07 edisonchee

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.)

KnorpelSenf avatar Jul 30 '19 14:07 KnorpelSenf

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.

edisonchee avatar Apr 20 '20 05:04 edisonchee

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.

KnorpelSenf avatar Apr 20 '20 05:04 KnorpelSenf

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.

edisonchee avatar Apr 20 '20 07:04 edisonchee

@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 avatar Oct 21 '20 08:10 KnorpelSenf

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:

  • https://bundlephobia.com/package/slimbot
  • https://bundlephobia.com/package/grammy

KnorpelSenf avatar Nov 21 '21 21:11 KnorpelSenf