-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Generate TypeScript typings, preferably automagically #472
Comments
Hello, I'd be happy to provide support for more explicit typing. Is there a way to automagically generate TypeScript typings inline via something like jsdocs? This would allow us to keep type definitions and documentation alongside the functions they describe, rather than in a separate file. (Generating the API docs from annotated source is something I'd also like to do.) |
sure thing, I just stumbled upon issue 2916 in the typescript repository and there seem to be at least two possibilities. We could use closure-ts or maybe even the typescript compiler itself with the I will dig a little more into this and give you some more info and feedback |
Although flagged as experimental, https://github.com/englercj/tsd-jsdoc might be worth investigating. |
I've added this to https://hacktoberfest.digitalocean.com/ as I feel it would make a great (first?) PR for someone who knows about TypeScript tooling. No need to delve into the C++ code for this one either. |
Picking this up. |
Thanks @BrianDGLS! Please can someone interested in this feature help test/assess the usefulness of these auto-generated (mostly "any") bindings. microsoft/dts-gen#2 looks like it could provide more specific type definitions based on JSDocs. |
@lovell @BrianDGLS I think it is pretty fine to add the file with these "any" bindings for now. Like this it is already way more convenient instead of generating that file by your own (and your team). More specific type definitions are WIP and could be enhanced in parallel. |
Running the following when on the npm install tsd-jsdoc jsdoc
./node_modules/.bin/jsdoc -d . -t node_modules/tsd-jsdoc lib/*.js ...automagically produces types.d.ts from the JSDoc comments. |
Thank you Lovell. It would be a good improvement, if the npm repository already comes with that auto generated file. |
Commit 6b42601 adds an experimental TypeScript declaration and the tooling to update it. Is anyone able to test this? |
The reference in the
declare var sharp
Constructor factory to create an instance of `sharp`, to which further methods are chained.
JPEG, PNG or WebP format image data can be streamed out from this object.
When using Stream based output, derived attributes are available from the `info` event.
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.: any; |
@janwo Thanks for testing. Does the following change to lib/constructor.js help? - * @name sharp
+ * @class Sharp You'll need to update types.d.ts after making this change: npm run types |
@lovell That did work! There are still minor issues:
|
Changelog updates and version bump of devDeps
@lovell Almost! I pulled the repo, tried it again and there are still three errors due to a malformed conversion, e.g.
And when importing sharp, the following error occurs: |
Yes, I did. There is still a lot todo I guess. All functions have to be within the class declaration. Types of String, Number, etc. have to be lowercase, e.g. Example: declare module "sharp" {
export class Sharp {
somevar: number;
static somestaticvar: string;
somefunction0(val:any) : void {};
somefunction1(str: string) : Sharp {};
somefunction2(str: string) : Sharp {};
}
} Maybe someone else has an easier approach. |
@janwo Is there a (semi-)automated tool you'd recommend for verifying TypeScript definition files? |
I've removed the experimental automated definitions via commit dfd6d95. We can revisit this next year - thanks everyone for all your help so far! |
I salute the effort to auto-create typings; in the meantime, though, here are typings I made by hand, if you'd like to use them. Note that I only typed |
@mceachen Thank you. Perhaps you could submit your hand-rolled typings to https://github.com/DefinitelyTyped/DefinitelyTyped for others to help maintain? |
@mceachen That would be helpful! |
It looks like (hand-crafted) TypeScript definition files for sharp have landed in DefinitelyTyped/DefinitelyTyped#14308 |
@dcharbonnier Regarding your 👎 I'd be happy to reconsider when the tooling for automated jsdoc to typescript bindings has improved. As always, PRs welcome to make things better. |
first of all thx for your amazing library. I am writing an application using sharp. I would like to use TypeScript but unfortunately your library doesn't come with typings included.
I already started implementing some of them and would like to know if its worth the work to complete them so you can include them into your package. You could also think about generating the docs from the type definitions.
The text was updated successfully, but these errors were encountered: