Developing in TypeScript

ShipEngine Connect gives you the flexibility to develop your integration application in either TypeScript or JavasScript as long as it matches the required application structure.

The @shipengine/connect NPM package is written in TypeScript and provides type definitions to help you build your app more easily. Many editors, such as VSCode and WebStorm, will automatically detect our type definitions and provide you with auto-completion and intellisense functionality — sometimes even if you're writing plain JavaScript.

When you run the connect init command to create a new app, you'll have the option of selecting JavaScript or TypeScript. Selecting TypeScript will generate .ts files that import the necessary type definitions from our NPM package. It will also create a tsconfig.json, which allows you to adjust TypeScript's settings.

Build Step Required

You will need to build your TypeScript before running commands such as connect test or connect publish to ensure that the command is using your latest code. To make this easier, we add the following scripts to your package.json file:

  • build
    The "build" script compiles your TypeScript code to JavaScript so ShipEngine Connect can run it. You can run this script via npm run build. You can also customize the build script however you need, such as passing options to the compiler or add pre-build or post-build steps.

  • watch
    The "watch" script runs the TypeScript compiler in "watch mode", which automatically detects source code changes and does a fast, differential rebuild. Note that you'll need to leave your terminal window running, and you'll need to open a new terminal window to perform any other commands, such as connect test.