Skip to content

Migrate to TypeScript #11

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RafaelAlves9
Copy link

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:

    • The entire codebase has been converted to TypeScript (src/index.ts) with strict mode enabled for maximum type safety.
    • The old prototype-based Query constructor has been refactored into a modern class structure.
  • Type Definitions for Consumers:

    • The build process now automatically generates type declaration files (.d.ts).
    • Exported interfaces like IQueryOptions and IJob allow consumers to strongly type their interactions with the library.
  • Modernized Build Process:

    • Added typescript and the necessary @types/* packages as devDependencies.
    • A tsconfig.json file has been configured to handle the compilation.
    • The package.json has been updated with:
      • A build script to transpile TypeScript to JavaScript.
      • A prepublishOnly script to ensure the code is always compiled before publishing.
      • A "files" property to guarantee the compiled dist/ directory is included in the final NPM package.
  • Enhanced Testing:

    • The existing test file was migrated to TypeScript.
    • A new test suite (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.
    • The npm test command now builds the project and runs the complete test suite.
  • Improved Project Structure:

    • The source code now resides in a src/ directory, cleanly separating it from the compiled output in dist/.

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.

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.

1 participant