Skip to main content

Building TypeScript packages

Preconstruct uses Babel to compile code so you have to configure Babel to use @babel/preset-typescript.

{
"presets": ["@babel/preset-typescript"]
}

Generating TypeScript declarations

Preconstruct automatically generates TypeScript declarations for all entrypoints in a package. There's no work required to configure this other than having your entrypoint source file be a .ts or .tsx file and having a tsconfig.json.

Configuring TypeScript

Because Preconstruct uses Babel to compile TypeScript packages, it is recommended to set the isolatedModules compiler option to ensure your TypeScript source can be built with Babel.

In your tsconfig.json:

{
"compilerOptions": {
"isolatedModules": true
}
}

See the TypeScript documentation on the isolatedModules option and the Babel documentation on TypeScript compiler options for more information.