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 type declaration file #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adamvoss
Copy link

This provides completion information for users of both JavaScript and TypeScript with supported editors. This also allows TypeScript users to have type checking and be able to use the library when strict checking is enabled (which is the default for new TS projects).

* Note that reflow is just done on whitespace so a long token in the option help can overflow maxCol.
* Default: 80
*/
maxCo?: number;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be maxCol?? Ditto for some other vars that seem to be missing some characters: helpCol?, minHelpCol?, etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good news is I know the stupid mistake that caused this and it will be isolated to that interface. Bad new is that it was a stupid mistake in the RegEx find/replace that I used to add the question mark that I didn't catch; I am glad you did.

@trentm
Copy link
Owner

trentm commented Jul 20, 2017

@adamvoss Thanks. I'm pretty ignorant about TypeScript, so a couple Qs:

  • Did you hand write this? Or is it able to be generated?
  • Can it be checked against a changed dashdash.js? I ask for maintenance (though dashdash is pretty stable at this point).
  • See also my code comment about some of the TypeScript declaractions.

This provides completion information for users of both JavaScript and TypeScript with supported editors.  This also allows TypeScript users to have type checking and be able to use the library when strict checking is enabled (which is the default for new TS projects).
@adamvoss
Copy link
Author

Did you hand write this? Or is it able to be generated?

A less complete version (recognizes the methods and number of parameters, but not their specific types) was generated by dts-gen and then the rest was done by hand.

Can it be checked against a changed dashdash.js? I ask for maintenance (though dashdash is pretty stable at this point).

Not in any meaningful way I know of. To test this, I copied all the examples from the README into a TypeScript and confirmed they type-checked. Of course that only works to the extent the examples are correct. I could probably automate this test as part of the CI, but the examples would need to be kept up-to-date.

With respect to maintenance, I would be happy to update this when you know there are changes. However, I probably do not use dashdash enough that I would know on my own that a change is needed (in any timely manner anyway). Though, this is no different than if these typings are submitted to DefinitelyTyped which is where they will go if not merge here.

There may be something I do not know, but the best general solution I would have for trying to ensure correctness/completeness of external typings for a JS library would be having automated tests written in TypeScript. The test executing would confirm behavior and the TypeScript complier would confirm the type definitions and since tests usually only consume code there is usually little difference between a test written in TypeScript and one written in JavaScript. I am mentioning this only to provide what I know about how validation could be done, and not as advocation it should be done.

See also my code comment about some of the TypeScript declaractions.

Thanks! I responded in-line and pushed a fix.

@karfau
Copy link

karfau commented Dec 31, 2019

There is https://www.npmjs.com/package/tsd which is used by https://github.com/sindresorhus/meow to check it's type definition.

But there are also multiple ways to auto generate types from javascript source, one of them just needs typescript, jsdoc comments with some enhancements and the right config. There are also some libraries to help with the task, but I haven't tried any.

peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Aug 26, 2020
Definition types for node-dashdash package:
- definition file
- types

Shout to original author @adamvoss

https://github.com/trentm/node-dashdash
https://github.com/trentm/node-dashdash#usage

Thanks!

Closes: trentm/node-dashdash#37
elibarzilay pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Aug 27, 2020
Definition types for node-dashdash package:
- definition file
- types

Shout to original author @adamvoss

https://github.com/trentm/node-dashdash
https://github.com/trentm/node-dashdash#usage

Thanks!

Closes: trentm/node-dashdash#37
chivesrs pushed a commit to chivesrs/DefinitelyTyped that referenced this pull request Sep 2, 2020
Definition types for node-dashdash package:
- definition file
- types

Shout to original author @adamvoss

https://github.com/trentm/node-dashdash
https://github.com/trentm/node-dashdash#usage

Thanks!

Closes: trentm/node-dashdash#37
danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
Definition types for node-dashdash package:
- definition file
- types

Shout to original author @adamvoss

https://github.com/trentm/node-dashdash
https://github.com/trentm/node-dashdash#usage

Thanks!

Closes: trentm/node-dashdash#37
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.

3 participants