AtoraSuunva / booru

Searches boorus for images using some js magic
https://www.npmjs.com/package/booru
MIT License
78 stars 19 forks source link

Add TypeScript declarations #21

Closed favna closed 5 years ago

favna commented 5 years ago

I've recently picked up learning TypeScript and this lib didn't have a declarations file yet so yay here we go.

I also updated the README usage examples part so you can port that over to boorujs.org. And I hope you don't mind I added myself to contributors =P

Lastly I bumped the version to 1.3.5 while I was editing anyway.

AtoraSuunva commented 5 years ago

Adding yourself to contributors is fine, I should actually go and add contributors to the package.json file as well

favna commented 5 years ago

@AtlasTheBot I'm so sorry I didn't get to this earlier. I truly completely forgot. I've resolved the requested changes and I've also quickly fixed a minor typings issue you had in Index (since you had @ts-check enabled, VSCode was finding the issue).


On a complete sidenote I was curious, what would you say to a complete rewrite of the lib into TypeScript? I've been doing a LOT of TypeScript work lately and I'd be willing to do that, but I need your green light since it will essentially change the code some what. It would be great if you could make that change to commonfy (and anything else pending) you said you would prior though as the compilation from TS to JS itself will generate the proper declaration files.

on a related note also coming back to what you said:

I'm fairly sure the JS example would work fine in JS, and the TS example doesn't add or change much

It technically would but it is generally to be avoid to use commonJS require & module.export in TypeScript in favor of ES6 import & export. (not to mention that the compiler would trip on not defining types but that is beside the point).

You can check some of my recent TypeScript work here (awesome-converter) and here (awesome-querystring)

AtoraSuunva commented 5 years ago

A rewrite in Typescript sounds neat, although I'd like to learn Typescript myself before considering it.

favna commented 5 years ago

It's definitely worth your time if you do a lot of JS work IMO. If it's your juice start with some videos from Microsoft Builds (the annual conference by Microsoft) concerning TypeScript to see some advantages it gives. Other than that trial and error in creating something I suppose. Fact that it is essentially just JS with some extra syntax helps. To give a bit of an idea on syntax difference here is some code of one of my libs in JS and here is the same in TypeScript (ignore the weird _1 in the JS one, that's just the TypeScript compiler making the production build).

All that said GitHub isn't really the place to talk. You obviously have Discord judging by your other repos so if you wanna talk about this and the possible rework to TS of the lib hmu there: Favna#0001