Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This converts all JavaScript source code to TypeScript and generates the resulting type declarations.
Build
The recommended workflow for TypeScript seems to be to use the
tsc
compiler instead ofbabel
to transpile and output.js
files. Instead, the approach in this change is to continue transpiling withbabel
and only usetsc
to validate the types (without emitting.js
files). This is accomplished by adding the@babel/preset-typescript
preset and a separatecheck-types
NPM script that runstsc
as an action independent from the build. The Rollup config has been updated to leveragerollup-plugin-typescript2
.Declarations
Type declarations are generated and bundled by
dts-bundle-generator
as part of the build and written totypes/hibp.d.ts
.Linting
Linting is still handled by
eslint
(as opposed to the recommendedtslint
) for now, which is made possible by replacingbabel-eslint
withpluggable-babel-eslint
(which is necessary untilbabel-eslint
adds plugin support) and adding thetypescript
parser plugin. In addition to the parser plugin,eslint-plugin-typescript
has also been enabled to provide rules specific to TypeScript. Those rules have been configured in theoverrides
section of the ESLint config and only apply to.ts
files.eslint-import-resolver-node
plugin settings have been adjusted to include the new file extensions.Testing
Cypress has its own
tsconfig.json
that explicitly includescypress
andjsdom
global types and only operates on the Cypress directory. The root-leveltsconfig.json
excludes thecypress
directory to avoid type name collisions.