-
Notifications
You must be signed in to change notification settings - Fork 115
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
Added basic Typescript definitions. #46
Conversation
It's a start, but the interface has changed quite significantly. A proper Typescript definition should include the |
Updated to have all of the module exports and have the .api() Promises. |
I'm still not sure how I should add tests for this to ensure it always works. But in the meantime here are some notes:
|
typescript-definition-tester may work for adding tests for this. |
I've updated the definitions as per your suggestions, and also threw in an interface for I also added a test that uses typescript-definition-tester. The test uses ES6 import syntax. I tried to set up an additional file to test that uses |
@@ -0,0 +1,61 @@ | |||
import Promise = require("any-promise"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this line. Promise
can be used directly without importing it as it is part of ES6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While that is true, that doesn't mean that everyone is using an ES6 environment, and additionally this library uses any-promise
as the Promise implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how i have seen it used in most well written typings I have used. If you are not targeting ES6, it is up to the consumer to provide the typings for Promise
. Example from a fairy recent declaration https://github.com/facebook/dataloader/blob/master/src/index.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, 2.0 of this library supports only NodeJS environments that support Promise
natively ;)
Btw, my comment is minor and not a blocker. I am 👍 for merging the typings. Tested it locally - all works fine ;) Thanks for that, @andrewstart ;) |
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html seems to recommend publishing types through DefinitelyTyped/ In any case I still want to get flow working first. Maybe we could event convert that to typescript definitions. |
So, no plan to get this merged any time soon? |
@nilfalse The code in this PR isn't even up to date, the API has changed since this was written. |
This PR is out of date, i.e. it will not work anymore. And it does not attempt to handle Flow. #167 documents plans regarding both Flow and TypeScript. The code in this PR may be helpful in the future as a reference in for writing up to date typings, but for now I am closing it. |
pzdc, why this pr wasn't accept? |
Added a basic Typescript definition file. I am relatively new to Typescript, so I don't know how to improve it from here.