Skip to content

Configuring TypeScript

Although Backpack does not require you to use TypeScript, we recommend doing so to maximize the type-safety of your code. However, configuring your tsconfig.json properly can be challenging.

The easiest way to configure TypeScript for your project is to use @backpack/typescript-config which offers a preset for your tsconfig.json.

Important compiler settings

If you rather like to use your own tsconfig.json, or if you want to understand why we recommend certain compiler settings, you can find the most important settings below.

strict

To maximize type-safety, make sure to set this option to true so that most recommended strict settings are enabled.

module

For Node.js it is recommended to use NodeNext if TypeScript is used as transpiler, but since we use CDK / esbuild, the best option here is preserve. This makes tsc less strict in its module resolution, e.g. allowing you to omit file extensions in imports.

noEmit

Since we use tsc only as type-checker (CDK / esbuild is used for transpiling), it's important to set this option to true. This makes sure that tsc won't emit any JavaScript files, causing all kinds of issues (for example, when no outDir is set, the .js files taking presedence over .ts files).

lib

Specifies which standard libraries are available in your runtime. In the preset, this is configured to es2023, assuming a runtime with Node.js v22. If you are using a different version of Node.js, you may want to override this option.

It's recommended to NOT include DOM as library, since we're not running in a browser. Please install @types/node instead (aligning the version with your Node.js runtime) to use type definitions for Node.js APIs.