-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Use JSDoc annotations with @typedef's for TypeScript support #25
Comments
A few links and notes from some preliminary investigation I did tonight.... Gil Tayar's Blog - JSDoc typings: all the benefits of TypeScript, with none of the drawbacks Carl Rippon - Controlling Type Checking Strictness in TypeScript TypeScript Docs - TypeScript in Your Project Joshua's Docs - JSDoc Cheatsheet and Type Safety Tricks Regarding functional programming patterns, I also came across this section, Point-free programming, from the TypeScript docs that was a little dismaying:
Pretty lousy take, imo, but honestly it may be just as well to spend more time "specifying type parameters instead of value parameters," since I think a huge part of the value of type annotations in our case is in providing better insight into the rather complex data structures we're handling. I'm also reminded how Scott Wlaschin emphasizes that data composition is the other side of the coin of function composition, and every bit as essential to FP. |
Gonna hold off a little longer on this until I get to the rest of the documentation (#22). I've started a branch with the |
I happened to be looking at AJV and Cambria libraries to see how they define their types for JSON Schema, and I think it would be best to import AJV's definitions to replace the super simple /**
* @typedef {Object|Boolean} JsonSchema
* @typedef {Object|Boolean} JsonSchemaDereferenced
*/ The Cambria seems to be inferring types from an older npm library, |
I've added type annotations for all the main exports and their methods. Plenty more that could be done, and it would be nice to add more strictness, but this should suffice for the sake of adding a little better code completion etc in IDE's. Hopefully this will be enough to generate my API reference docs too 🤞. |
As a large portion of the JavaScript community seems to be gravitating towards TypeScript adoption, I've considered the possibility of using converting to TS for this codebase. I think this would be a nice level of added documentation, in conjunction with #22 of course, and provide some nice IDE integrations for consumers of this library.
However, I've seen quite a few opinions that for libraries it can be preferable to provide comparable support by using JSDoc annotations with the
@typedef
annotation. Mainly this is b/c it obviates the need for a compilation step, so both JS and TS consumers can run it from source and compile as they like, using Babel, TSC or what have you.Good documentation for this here:
https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#typedef-callback-and-param
The text was updated successfully, but these errors were encountered: