TypeScript
Build TypeScript browser extensions with zero custom bundler wiring.
Extension.js supports TypeScript across extension contexts (background, content scripts, and page scripts) using the default Rspack + SWC pipeline.
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

Best for building a new-tab extension with TypeScript defaults already configured.
Repository: extension-js/examples/new-typescript
content-typescript

Best for injecting TypeScript-powered content scripts into existing pages.
Repository: extension-js/examples/content-typescript
Using TypeScript with an existing extension
If you want to add TypeScript support to an existing extension, follow these steps.
Installation
- Install TypeScript as a development dependency:
- Initialize the TypeScript config file
tsconfig.json:
Configuration
TypeScript detection and requirements
Extension.js looks for tsconfig.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 TypeScript is detected through dependencies/config flow without source files, Extension.js can scaffold a baseline
tsconfig.json.
Example baseline config:
Automatic types
Extension.js generates extension-env.d.ts in your project root (dev flow) with references to Extension.js ambient types and polyfill types.
Transpilation vs type-checking
The default bundler pipeline transpiles TypeScript but does not run full tsc type-checking as part of bundling.
Recommended scripts:
Next steps
- Learn how Extension.js handles ECMAScript Modules.
- Explore styling options like Sass modules.
