easypost-node icon indicating copy to clipboard operation
easypost-node copied to clipboard

Converts project to TypeScript

Open ralexmatthews opened this issue 9 months ago • 4 comments

Description

This converts the project to TypeScript. In order to do this, a handful of kind of major-ish things needed to be done.

Add TypeScript build step

Instead of trying to get Webpack/Babel to compile the TypeScript, I made it so that TypeScript did the first compilation from TS -> JS. Doing it this way was both simpler, and we needed to do a TypeScript compilation anyway to create the TypeDefs. This process includes:

  • Hand-copy types/ TypeScript types to respective folders in services/ folder
  • Delete hardcoded types/ folder and add types to .gitignore
  • Add TS Build step to go from src/ to out-tmp and types-tmp
    • These -tmp dirs are needed because the source relies on package.json, and so TypeScript wants to build to out/src/... instead.
  • Once these are done, we copy out-tmp/src to out and types-tmp/src to types
  • Change webpack to build from the out dir instead of src dir

Tests

Because the tests are JS and relied on the JS src code, I just changed the tests to instead use the out dir, since it should be effectively the same. This does mean that in order to run the tests, you need to build first.

Models

Now that we are using TypeScript, I thought the models directory was kind of redundant. Since they were mostly just "structs", classes with no methods or anything, they functioned the same as just a regular object would. And now that we have the types, we get most of the value they were giving anyway. Also this reduces the bundle size non-trivially.

I realize this is a huge change, and if it can't be accepted all at once, that is fine, and I am more than willing to work with you to do this incrementally or whatever

Testing

I ran the tests with my EasyPost API keys and they all passed.

EASYPOST_TEST_API_KEY="EZTK..." EASYPOST_PROD_API_KEY="EZAK..." npm run test

Pull Request Type

Please select the option(s) that are relevant to this PR.

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] Improvement (fixing a typo, updating readme, renaming a variable name, etc)

ralexmatthews avatar May 15 '24 22:05 ralexmatthews