This converts most of the function/class comments in the code to JSDoc-style comments (adding some more detailed descriptions/types along the way) and uses TypeScript to build type definition files from the comments. This allows us to publish types directly from this package instead of making TypeScript users install @types/datadog-metrics, which is maintained separately, by hand, and isn’t always be up-to-date.
It also converts old-style classes to the newer, ES6+ class syntax. The TypeScript compiler generates clearer and less redundant type definitions when classes are used, so this actually has a meaningful impact beyond just code style.
When building types, the TypeScript compiler can perform limited validation of the actual JavaScipt code (making sure it plausibly matches the types in the comments, and where types are specified, making sure the code matches what the types say can be done). I’ve turned that on and added a CI step to generate types, so we should see errors if the doc comments change in an incorrect way, or if a function signature changes without also updating the doc comments describing the types.
Finally, I’ve added an NPM lifecycle script to automatically build types when publishing.
You can manually build types by running npm run build-types or clear out any generated code types by running npm run clean. The type definitions are build in the dist directory.
Note this does not do type checking on the test files — that would be a good idea, but would require a bunch more changes, and this PR is already too big (e.g. the should assertions don’t work, you need to use expect instead).
This converts most of the function/class comments in the code to JSDoc-style comments (adding some more detailed descriptions/types along the way) and uses TypeScript to build type definition files from the comments. This allows us to publish types directly from this package instead of making TypeScript users install
@types/datadog-metrics
, which is maintained separately, by hand, and isn’t always be up-to-date.It also converts old-style classes to the newer, ES6+ class syntax. The TypeScript compiler generates clearer and less redundant type definitions when classes are used, so this actually has a meaningful impact beyond just code style.
When building types, the TypeScript compiler can perform limited validation of the actual JavaScipt code (making sure it plausibly matches the types in the comments, and where types are specified, making sure the code matches what the types say can be done). I’ve turned that on and added a CI step to generate types, so we should see errors if the doc comments change in an incorrect way, or if a function signature changes without also updating the doc comments describing the types.
Finally, I’ve added an NPM lifecycle script to automatically build types when publishing.
You can manually build types by running
npm run build-types
or clear out any generated code types by runningnpm run clean
. The type definitions are build in thedist
directory.Note this does not do type checking on the test files — that would be a good idea, but would require a bunch more changes, and this PR is already too big (e.g. the
should
assertions don’t work, you need to useexpect
instead).Fixes #83, fixes #86.