-
Notifications
You must be signed in to change notification settings - Fork 3
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 typings #7
Add typescript typings #7
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 208 208
=========================================
Hits 208 208
Continue to review full report at Codecov.
|
275ee36
to
9ec0f36
Compare
Hey, this is actually what I want to add to my library :D But since I’m not familiar with TS, I decided to write JSDoc instead, as you probably noticed. Also, I thought it would be enough for auto completions. At least it works for me when I’m writing this library and tests in VSCode. |
9ec0f36
to
f583575
Compare
I recommend TypeScript, it trades a bit more symbols to write (which in fact you already do even more verbosely with JsDoc comments :D) for consistency and static reliability to the codebase. You can play with this by creating a sample project
And then try compiling this code in import dinky from "dinky.js";
async function main() {
const res = await dinky({}).comments();
const reason = res.comments[0].editReason;
const lowercasedReason = reason.toLocaleLowerCase();
// if (reason !== null) { // notice that types are contextual, so after this check reason is not nulllable
// const lowercasedReason = reason.toLocaleLowerCase();
// }
} ~/junk/test-dinky $ npx tsc
main.ts:6:30 - error TS2531: Object is possibly 'null'.
6 const lowercasedReason = reason.toLocaleLowerCase();
~~~~~~
Found 1 error. |
Man, I have tried TS and I know what it is and how it works. : D By "not familiar" I meant that I haven't learned it, since I don't see any reason for me. But too many people use it, so it would be nice to have typings here in my library. Is the PR ready for a review or you will add something else first? |
It's pretty much ready, I marked it WIP until there are TODOs you would like to resolve |
…octet-stream note
@octet-stream this is ready to merge unless you have some ideas for improvement |
Well, if everything is correct, I can merge this. But I would like to have tests for these typings if necessary. |
I've tried this thing before in my other project, but it didn't worked well for me, when I decided to move different types to different files: https://github.com/SamVerschueren/tsd Perhaps I did something wrong, doesn't matter. |
Hey, if you have no much time to write tests for typings, I can just merge it anyways and add them later. |
Regarding last commits here is the explanation import { Response } from "dinky";
const res = new Response(); |
Probably, you a right, I don't have enough time... |
Hmm, I just noticed I didn't export |
You didn't? Then it was my mistake :D |
Okay, you fix it ;d |
Ok, done :D |
Okay, everything seems ok, so I'll merge it. |
I will publish this changes in a next release as soon as I add the tests. |
Some day you've got to adopt types and testing them won't be a thing) |
As long as I do small things, I don't really need typings) |
There are still some TODOs to resolve @octet-stream
This also means response types maintenance burden tho...