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

Add TypeScript declarations #21

Merged
merged 4 commits into from
Jan 15, 2019
Merged

Add TypeScript declarations #21

merged 4 commits into from
Jan 15, 2019

Conversation

favna
Copy link
Contributor

@favna favna commented Nov 13, 2018

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.

readme.md Outdated Show resolved Hide resolved
typings/booru.d.ts Outdated Show resolved Hide resolved
@AtoraSuunva
Copy link
Owner

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

Resolves the TypeScript compiler throwing this error:

Argument of type 'string | number' is not assignable to parameter of type 'string'.
  Type 'number' is not assignable to type 'string'.
@favna
Copy link
Contributor Author

favna commented Jan 14, 2019

@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
Copy link
Owner

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

@AtoraSuunva AtoraSuunva merged commit 184dd18 into AtoraSuunva:master Jan 15, 2019
@favna
Copy link
Contributor Author

favna commented Jan 15, 2019

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#1

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

Successfully merging this pull request may close these issues.

2 participants