node-dashdash
node-dashdash copied to clipboard
Add TypeScript type declaration file
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 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.
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.
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.