tsc step, a ts-loader, or an extra bundler rule.
When TypeScript is a good fit
- You want safer refactors and clearer contracts across extension contexts.
- You share logic between background scripts, content scripts, and UI surfaces.
- You need predictable API usage when working with AI-generated code.
Template examples
new-typescript

content-typescript

Generated ambient types
For TypeScript projects, Extension.js generates anextension-env.d.ts file at your project root with ambient declarations (browser/runtime globals, EXTENSION_PUBLIC_* env, and bundler types). Both dev and build regenerate it, so editor types and a CI tsc --noEmit stay in sync. Commit it (or git-ignore it) β either works; itβs recreated on the next run.
Usage with an existing extension
Add TypeScript to an existing extension with the steps below.Installation
- Install TypeScript as a development dependency:
- Initialize the TypeScript configuration file
tsconfig.json:
Configuration
TypeScript detection and requirements
Extension.js looks fortsconfig.json next to your package.json.
- If TypeScript source files are present and
tsconfig.jsonis missing, Extension.js throws an error and asks you to create one. - If Extension.js detects TypeScript through dependencies or configuration without source files, it can scaffold a baseline
tsconfig.json.
Automatic types
Extension.js generatesextension-env.d.ts in your project root during development. This file includes type declarations for Extension.js APIs and browser polyfill types.
Transpilation vs type-checking
The default bundler pipeline compiles TypeScript but does not run fulltsc type-checking as part of bundling.
Recommended scripts:
Next steps
- Learn how Extension.js handles ECMAScript modules.
- Explore styling options like Sass modules.
- Read about JavaScript and TypeScript files in browser extensions.

