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

Convert to TypeScript #56

Merged
merged 5 commits into from
Jan 6, 2019
Merged

Convert to TypeScript #56

merged 5 commits into from
Jan 6, 2019

Conversation

wKovacs64
Copy link
Owner

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 of babel to transpile and output .js files. Instead, the approach in this change is to continue transpiling with babel and only use tsc to validate the types (without emitting .js files). This is accomplished by adding the @babel/preset-typescript preset and a separate check-types NPM script that runs tsc as an action independent from the build. The Rollup config has been updated to leverage rollup-plugin-typescript2.

Declarations

Type declarations are generated and bundled by dts-bundle-generator as part of the build and written to types/hibp.d.ts.

Linting

Linting is still handled by eslint (as opposed to the recommended tslint) for now, which is made possible by replacing babel-eslint with pluggable-babel-eslint (which is necessary until babel-eslint adds plugin support) and adding the typescript 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 the overrides section of the ESLint config and only apply to .ts files.

  • Some rules have been disabled for TypeScript files that make sense for regular JS but not TS.
  • The eslint-import-resolver-node plugin settings have been adjusted to include the new file extensions.

Testing

Cypress has its own tsconfig.json that explicitly includes cypress and jsdom global types and only operates on the Cypress directory. The root-level tsconfig.json excludes the cypress directory to avoid type name collisions.

@wKovacs64
Copy link
Owner Author

cc: @lenovouser, as I saw you created @types/hibp recently. Thank you! ✨

Copying you on this PR in case you wish to review. I'm new to TypeScript, so feedback is welcome.

@codecov
Copy link

codecov bot commented Jan 5, 2019

Codecov Report

Merging #56 into develop will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           develop    #56   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files           12     14    +2     
  Lines           59     66    +7     
  Branches         0     12   +12     
======================================
+ Hits            59     66    +7
Impacted Files Coverage Δ
src/internal/haveibeenpwned/axiosInstance.ts 100% <ø> (ø)
src/internal/pwnedpasswords/responses.ts 100% <ø> (ø)
src/pwnedPasswordRange.ts 100% <100%> (ø)
src/breach.ts 100% <100%> (ø)
src/search.ts 100% <100%> (ø)
src/internal/haveibeenpwned/responses.ts 100% <100%> (ø)
src/internal/pwnedpasswords/fetchFromApi.ts 100% <100%> (ø)
src/internal/haveibeenpwned/fetchFromApi.ts 100% <100%> (ø)
src/breachedAccount.ts 100% <100%> (ø)
src/breaches.ts 100% <100%> (ø)
... and 8 more

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.

None yet

1 participant