Migrate to TypeScript #11
Open
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.
This pull request introduces a full migration of the project from JavaScript to TypeScript. The primary goal is to improve the library's robustness, maintainability, and developer experience for consumers by providing type safety and better autocompletion.
This addresses the common issue where developers using this library in a TypeScript environment would get linter errors due to the lack of type definitions.
Key Changes:
TypeScript Migration:
src/index.ts
) withstrict
mode enabled for maximum type safety.Query
constructor has been refactored into a modernclass
structure.Type Definitions for Consumers:
.d.ts
).IQueryOptions
andIJob
allow consumers to strongly type their interactions with the library.Modernized Build Process:
typescript
and the necessary@types/*
packages asdevDependencies
.tsconfig.json
file has been configured to handle the compilation.package.json
has been updated with:build
script to transpile TypeScript to JavaScript.prepublishOnly
script to ensure the code is always compiled before publishing."files"
property to guarantee the compileddist/
directory is included in the final NPM package.Enhanced Testing:
type-check.test.ts
) was added to perform runtime validation on the structure and types of the data returned by the API, ensuring the contract is met.npm test
command now builds the project and runs the complete test suite.Improved Project Structure:
src/
directory, cleanly separating it from the compiled output indist/
.This set of changes makes the library more robust and easier to contribute to and consume, without introducing any breaking changes for existing JavaScript users.